Powers of 2
Updated
Problem statement
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
isPower(arr: int[]) → int[]
Complete the function isPower in the editor below.
isPower has the following parameter(s):
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
Examples
Example 1
arr = [1, 3, 8, 12, 16]return = [1, 0, 1, 0, 1]1 = 2^0, 8 = 2^3 and 16 = 2^4. The return array is [1, 0, 1, 0, 1].
Constraints
1 ≤ n ≤ 1000 ≤ arr[i] ≤ 5 x 10^7
More Oracle interview questions
- Course ScheduleONSITE INTERVIEW · Seen Nov 2026
- Shortest Subarray with Sum at Least KONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Minimum Meeting RoomsONSITE INTERVIEW · Seen Nov 2026
- Shortest Window with Required CountsONSITE INTERVIEW · Seen Nov 2026
- Maximum Subarray Sum with One DeletionONSITE INTERVIEW · Seen Nov 2026
- Shortest Deletion for Distinct CharactersONSITE INTERVIEW · Seen Nov 2026
- Count Dropped Rate-Limited RequestsONSITE INTERVIEW · Seen Nov 2026
- Remove Parentheses from a Plus-Minus ExpressionPHONE SCREEN · Seen Nov 2026
- Design Authentication ManagerONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Minimum Testers to Find the Poisoned BottleWalleye Capital · OA
- Address on Same PageNVIDIA · OANVIDIA interview questions
- Find the Missing Number from 1 to nGEP · OA
- Invert Ad Visibility BitsJP Morgan Chase · OAJP Morgan Chase interview questions
- Count Times Using at Most Two DigitsLSEG · OALSEG interview questions
- Minimum Tokens RemainingMicrosoft · OAMicrosoft interview questions
- Minimum Operations to Make Binary PalindromicGoogle · OAGoogle interview questions
- Find the Lowest Set Bit PositionExpedia · OA · ONSITE INTERVIEWExpedia interview questions
- Knights, Knaves and Their StatementsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Repeated Mirror XORMathWorks · OAMathWorks interview questions