
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"]
andn2 = ["2", "15"]
, the output should beComparePowers(n1, n2) = 1
.n1 = 210 = 1024
,215 = 32768
, son1 < n2
.
Input/Output
-
[execution time limit] 0.5 seconds
-
[input] array.string n1
A positive integer given as
["a", "b"]
, wheren1 = ab
.1 ≤ n1[0] ≤ 251
,2 ≤ n1[1] ≤ 251
. -
[input] array.string n2
A positive integer given as
["a", "b"]
, wheren2 = ab
.1 ≤ n2[0] ≤ 251
,2 ≤ n2[1] ≤ 251
. -
[output] integer
-1
,0
or1
.
Post Comment