Order Powers of Two and Three
Updated
Problem statement
You are given an integer upper. Return every integer x between 1 and upper, inclusive, that is a power of two or a power of three.
For this exercise, a qualifying value satisfies x = 2^a or x = 3^b, where the exponent is a nonnegative integer. This is the union of the two pure-power sequences. It does not include every product of the two bases: for example, 6 and 12 do not qualify.
Return the distinct qualifying values in strictly increasing order. The value 1 = 2^0 = 3^0 appears only once. Include upper when it qualifies. If upper = 0, return an empty array.
Use fresh local state and return a new array for each call. All values and comparisons are exact integers; do not rank values by a Collatz process or use approximate logarithms to decide membership.
Function
orderedPowers(upper: int) → int[]Examples
Example 1
upper = 10return = [1,2,3,4,8,9]The powers at most 10 are 1,2,4,8 from base two and 1,3,9 from base three. Their distinct sorted union is [1,2,3,4,8,9]. The mixed product 6 is excluded.
Example 2
upper = 0return = []Every qualifying value is positive, so a cap of 0 gives an empty result.
Example 3
upper = 81return = [1,2,3,4,8,9,16,27,32,64,81]Both 64 = 2^6 and 81 = 3^4 qualify. The cap is inclusive, so the result ends with 81; the shared value 1 occurs once.
Constraints
upperis an integer with0 <= upper <= 1000000000.- Exponents are nonnegative integers; qualifying values are pure powers of two or three.
- The result contains at most
48values. Every returned value fits a signed 32-bit integer. - Temporary candidate multiplication may exceed the cap. Use a sufficiently wide integer type or check the bound before multiplying.
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
- Find All Pythagorean TripletsDell Technologies · PHONE SCREENDell Technologies interview questions
- Sort a Quadratic-Transformed ArrayLinkedIn · PHONE SCREENLinkedIn interview questions
- Count Centaur Friend RequestsMeta · PHONE SCREENMeta interview questions
- Pythagorean Triple with Array MultiplicityByteDance · ONSITE INTERVIEWByteDance interview questions
- Employee Count Median, Mean and ModeClay · PHONE SCREEN
- Squares of a Sorted ArrayInstacart · PHONE SCREENInstacart interview questions
- Three Points in a Semicircle: Monte Carlo EstimateSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Merge Two Sorted ArraysCapgemini · PHONE SCREENCapgemini interview questions
- Squares of a Sorted ArrayStryker · PHONE SCREEN
- Squares of a Sorted ArrayGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
Interview reports that mention this question
Akuna Capital interview experiences
- Akuna Capital Quant Trader and QR Interviews: 5 Experiences
- Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
- Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
- Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
- Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)