Loading Now

comparePowers

Do you know what number is larger,  210 or 215?
Of course you do. What about, say 210 and  310? I bet you know this one too.
But what if I don’t give you a number explicitly, but in a form of exponentiation?

Give numbers n1 and n2 as exponentiations, determine which one is larger. If n1 > n2, return -1. If n1 = n2, return 0. Finally, if n1 < n2, return 1.

Be warned! The numbers can be quite large, so your solution should be efficient enough to pass all test cases.

Example

  • For n1 = ["2","10"] and n2 = ["2", "15"], the output should be ComparePowers(n1, n2) = 1.

    n1 = 210 = 1024215 = 32768, so n1 < n2.

Input/Output

  • [execution time limit] 0.5 seconds

  • [input] array.string n1

    A positive integer given as ["a", "b"], where n1 = ab.
    1 ≤ n1[0] ≤ 251, 2 ≤ n1[1] ≤ 251.

  • [input] array.string n2

    A positive integer given as ["a", "b"], where n2 = ab.
    1 ≤ n2[0] ≤ 251, 2 ≤ n2[1] ≤ 251.

  • [output] integer

    • -1, 0 or 1.

Post Comment

Contact