Description
Solutions
Submission
Powers of 2
🔥 FULLTIME

Given an array of integers, determine whether each is a power of 2, where powers of 2 are [1, 2, 4, 8, 16, 32, 64...]. For each integer evaluated, append to an array a value of 1 if the number is a power of 2 or 0 otherwise.

Function Description

Complete the function isPower in the editor below.

isPower has the following parameter(s):

  1. int arr[n]: an array of integers

Returns

int[n]: array of binary integers where each index i contains a 1 if arr[i] is a power of 2 or a 0 if it is not

Example 1:

Input:  arr = [1, 3, 8, 12, 16]
Output: [1, 0, 1, 0, 1]
Explanation:

1 = 2^0, 8 = 2^3 and 16 = 2^4. The return array is [1, 0, 1, 0, 1].

Constraints:
    • 1 ≤ n ≤ 100
    • 0 ≤ arr[i] ≤ 5 x 10^7
Thumbnail 0
Testcase

Result
Case 1

input:

output: