Powers of Two in a Range
Updated
Problem statement
Given two integers a and b, return every power of two from a to b, with both ends included, in increasing order.
A power of two is an integer of the form 2^k, where k is zero or more. This includes 1 = 2^0. Return an empty array if no power of two falls in the range.
Python follow-up: try writing the same selection as a list comprehension. Only the values your function returns are checked.
Function
powersOfTwo(a: int, b: int) → int[]Examples
Example 1
a = 2b = 16return = [2,4,8,16]For a = 2 and b = 16, the powers of two are 2, 4, 8 and 16, which are 2^1 up to 2^4. Both endpoints are included, so the answer is [2,4,8,16].
Example 2
a = 5b = 9return = [8]Only 8 = 2^3 lies between 5 and 9, so the answer is [8].
Example 3
a = 3b = 3return = []The only integer in the range is 3, which is not a power of two, so the answer is an empty array.
Constraints
0 <= a <= 10000000000 <= b <= 1000000000a <= b
More Akuna Capital Phone Screen questions
- Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Biased Coin: Probability of Exactly h HeadsPHONE SCREEN · Seen Nov 2026
- Positive Nth Root with Gradient DescentPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Two SumOA · PHONE SCREEN · Seen Sep 2026
- Maximum Value in a Binary TreePHONE SCREEN · Seen Sep 2026
- Tiered Expiring Item StorePHONE SCREEN · Seen Aug 2026
- Statistics for the Latest K ValuesPHONE SCREEN · Seen Nov 2025
- Remove Duplicates While Preserving OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2025
- Sliding Window MaximumPHONE SCREEN · Seen Oct 2025
- Evaluate a PolynomialPHONE SCREEN · Seen Oct 2025
Similar questions at other companies
- Count the 1 Bits in a 32-Bit ValueAmazon · PHONE SCREEN
- Even or Odd Without DivisionAdobe · PHONE SCREENAdobe interview questions
- Power of Two Without DivisionArm · PHONE SCREEN
- Choose the Next Minesweeper ActionRunloop · PHONE SCREEN
- IP Address to CIDR BlocksOpenAI · PHONE SCREENOpenAI interview questions
- Fewest Games to Find the Top Two TeamsSusquehanna International Group (SIG) · PHONE SCREENSusquehanna International Group (SIG) interview questions
- Minimum Testers to Find the Poisoned BottleWalleye Capital · OA
- Address on Same PageNVIDIA · OANVIDIA interview questions
- Find the Missing Number from 1 to nHyperVerge · ONSITE INTERVIEW
- Find the Missing Number from 1 to nGEP · OA