
powersOfTwo
Mr. Privalov has a number k
and an array of n
elements, each element of which is the power of 2
and doesn’t exceed 2k
. All powers from 20
to 2k
are appear in the array (maybe even more than once) except one, which Mr. Privalov wants to find.
Your task is help to Mr.Privalov to find a missed power.
Example
- For
k = 1
andarr = [1, 1]
, the output should bepowersOfTwo(k, arr) = 2
; - For
k = 3
andarr = [8, 4, 2]
, the output should bepowersOfTwo(k, arr) = 1
Input/Output
- [execution time limit] 0.5 seconds
-
[input] integer k
The maximum power of two.
Constraints:1 ≤ k ≤ 30
.
-
[input] array.integer arr
Array of powers of two. It is guaranteed that the length of the array is
n
, all its elements are powers of two not greater than2k
, and there is exactly one missing power in it.
Constraints:1 ≤ arr.length ≤ 100
. -
[output] integer
- The missing power.
Post Comment