Reported September 2026
Visabit manipulation

Minimum Power-of-Two Removal Operations

Reported by candidates from Visa's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Visa OA. Under 2s to a working solution.
Founder's read

The data structure this Visa problem hinges on is a plain frequency array indexed by exponent, and the rest is binary addition. Visa reported this one in September 2026. It's called Minimum Power-of-Two Removal Operations. It looks like a partition puzzle, but it's really bit counting in disguise. If you read it as subset search, you'll burn your whole window on backtracking that can't work at n up to 10^5. Once you see the carry trick, the code is about ten lines. If your mind goes blank when the OA clock starts, StealthCoder runs invisibly on your screen and gives you the solution as a safety net.

The problem

You are given an integer array arr of length n. You may perform the following operation any number of times until the array becomes empty:
Let m be the current size of the array.
Choose an integer k such that 1 <= k <= m, and remove any k elements from the array.
The removal is allowed only when the chosen elements satisfy 2^arr[i1] + 2^arr[i2] +... + 2^arr[ik] = 2^p for some integer p >= 0.
You may remove elements from any positions; they do not need to be consecutive. The exponent p may differ between operations.
Return the minimum number of operations required to remove every element from the array.

Function
findMinOperations(arr: int[]) → int

Examples
Example 1
arr = [1,1,3,2,3]
return = 2
Remove the elements at positions 1, 2, and 4. Their sum is 2^1 + 2^1 + 2^2 = 2^3, leaving [3,3].
Remove the two remaining elements because 2^3 + 2^3 = 2^4.
The array is empty after two operations.
Example 2
arr = [1,1,3,5]
return = 3
Remove the two values 1 together because 2^1 + 2^1 = 2^2. The values 3 and 5 must then be removed in separate operations, so the minimum is 3.
Example 3
arr = [0,0,0,0]
return = 1
All four elements can be removed together because 2^0 + 2^0 + 2^0 + 2^0 = 2^2.

Constraints
1 <= n <= 10^5.
0 <= arr[i] <= 10^6.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: add up every 2^arr[i] as one huge binary number S. Any group that sums to a power of two contributes one set bit at most, and merging k powers of two can never produce more than k set bits. So the answer is at least popcount(S). It's also achievable, because you can always split the elements to match each set bit of S. Don't build S directly, since exponents reach 10^6. Instead, count occurrences per exponent in an array a bit longer than the max value. Walk from low to high. At index i, carry cnt[i] / 2 into i+1. If cnt[i] is odd, add one to the answer. The common pitfall is forgetting the carry can run past the max exponent by about 17 positions. Check it against example 1: the sum is 24 = 11000 in binary, so the answer is 2. StealthCoder is the hedge if the live OA makes you forget this reduction.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Minimum Power-of-Two Removal Operations 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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Visa's OA.

Visa reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minimum Power-of-Two Removal Operations FAQ

What's the actual trick in Minimum Power-of-Two Removal Operations?+

Treat the sum of all 2^arr[i] as one big binary number. The minimum number of operations equals the number of set bits in that sum. You never build the number. You simulate the carries using a count per exponent, halving and pushing up.

Why is the answer exactly the popcount of the total sum?+

Each operation removes elements summing to a single power of two, which is one set bit. Combining k powers of two yields at most k set bits, so you need at least popcount(S) groups. You can always split the elements to match each bit, so that lower bound is reachable.

How do I handle exponents up to 10^6 without overflow?+

Don't compute 2^x at all. Use an integer array of size max(arr) plus about 20 and count occurrences per exponent. Then sweep upward, carrying cnt[i] / 2 into cnt[i+1] and counting odd positions. The extra length covers carries beyond the max exponent.

What's the time complexity I should aim for for Visa's version?+

Linear, O(n + max(arr)). One pass to count, one pass to carry and tally odd positions. With n up to 10^5 and values up to 10^6, anything involving subset search or sorting pairs will be too slow or just wrong.

How do I prepare for this in 48 hours?+

Work three small cases by hand: [0,0,0,0], [1,1,3,5], and [1,1,3,2,3]. Convert each to a binary sum and count bits. Then write the carry loop from memory once. Practice the edge case of carries extending past the largest exponent.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Visa.

OA at Visa?
Invisible during screen share
Get it