Power of 2

Find if Given number is power of 2 or not.
More specifically, find if given number can be expressed as 2^k where k >= 1.

Input:

number length can be more than 64, which mean number can be greater than 2 ^ 64 (out of long long range)

Output:

return 1 if the number if a power of 2 else return 0

Example:

Input : 128
Output : 1
Interview Code Editor
Hints
  • Hint 1
  • Solution Approach
  • Complete Solution
3133 successful submissions.
Asked In:
  • Amazon
Click here to jump start your coding interview preparation