Minimum Values with Even Powers of Two
Reported by candidates from Visa's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The weird part of this Visa question, reported in September 2026, is that 4 returns -1 while 5 returns 2. It looks like a coin-change problem, and that's the trap. Each value x must split into exactly one tiny summand (1, 2, or 3) plus any number of powers of 4. Candidates who reach for dynamic programming burn time on arrays up to 2 * 10^5 values as large as 10^9. It's a math and greedy problem in disguise, and the solution is about ten lines. If your head goes blank mid-assessment, StealthCoder runs invisibly as a safety net and reads the problem for you.
The problem
For each value x in the integer array arr, find the minimum positive integer k such that x can be written as a sum of exactly k positive integers under these rules: Exactly k - 1 summands are powers of two with positive even exponents: 4, 16, 64,.... A value may be used more than once. Exactly one summand is less than 4, so it must be 1, 2, or 3. If no valid representation exists, return -1 for that value. Return the answers in the same order as arr. Function getMinimumValues(arr: int[]) → int[] Examples Example 1 arr = [5,1,4,6,10] return = [2,1,-1,2,3] The valid minimum representations include 5 = 1 + 4, 1 = 1, 6 = 2 + 4, and 10 = 2 + 4 + 4. The value 4 cannot include exactly one summand smaller than 4, so its answer is -1. Example 2 arr = [2,3,7,21,64] return = [1,1,2,3,-1] The values 2 and 3 each use one small summand. Also, 7 = 3 + 4 and 21 = 1 + 4 + 16. A multiple of 4, such as 64, cannot satisfy the required small summand. Constraints 1 <= arr.length <= 2 * 10^5. 1 <= arr[i] <= 10^9.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Every power of 4 with a positive exponent is a multiple of 4. So the small summand s has to equal x mod 4, and it must be 1, 2, or 3. If x mod 4 is 0, return -1 immediately. Otherwise subtract s and divide by 4 to get m. Now you're writing m as a sum of powers of 4 (1, 4, 16, and so on) using the fewest terms. Powers of 4 form a canonical coin system, so greedy works, and the count is just the digit sum of m in base 4. The answer is 1 plus that digit sum. Check 21: s=1, m=5, which is 11 in base 4, so 1+2=3. The pitfall is brute-force DP per value, which times out. Loop with m % 4 and m / 4, per element. If you freeze on the live OA, StealthCoder is your hedge.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Minimum Values with Even Powers of Two cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Visa's OA.
Visa reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimum Values with Even Powers of Two FAQ
What's the trick in the Visa even powers of two problem?+
Every allowed big summand is a multiple of 4, so the small summand is forced to be x mod 4. If that's 0, answer is -1. Otherwise divide the rest by 4 and count how many powers of 4 you need. That count is the base-4 digit sum.
Why is greedy correct here?+
Powers of 4 are each a multiple of the previous one, so taking the largest coin never hurts. Equivalent view: any base-4 digit above 3 can be carried into the next place for fewer terms. So the minimum count is the digit sum of m in base 4.
How hard is this Visa OA question really?+
Easy once you spot the mod 4 observation, medium if you don't. The code is short. The difficulty is noticing the structure instead of building a DP table. With 2 * 10^5 inputs up to 10^9, per-value work must be about log base 4 of x.
Which edge cases should I test before submitting?+
Test x = 1, 2, 3 (answer 1), any multiple of 4 like 4 or 64 (answer -1), and x = 7 (answer 2). Also test a large value near 10^9 to confirm no overflow. Return answers in the original order of arr.
Can I prep this in 48 hours?+
Yes. Spend an hour on base conversion and digit sums, plus why greedy works for coin systems where each coin divides the next. Then write this solution from memory once. Practice reading statements for forced values like the small summand, because that's what unlocks the problem.