Reported April 2026
Visagreedy

Maximize Capped Contribution Sum

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

Visa's April 2026 OA asks you to maximize a sum by selectively doubling array values. You have two arrays a and b, and you can pick at most k indices to double the b values before calculating contributions. Each index contributes min(a[i], b[i]) or min(a[i], 2*b[i]) depending on whether you doubled it. The trap is figuring out which k indices actually give you the biggest bump. If you blank on the greedy choice during the live OA, StealthCoder will feed you the pattern in real time.

The problem

You are given two integer arrays a and b of the same length and an integer k. For each index i, that index contributes min(a[i], b[i]) to a total sum. You may choose at most k distinct indices. For each chosen index, replace b[i] with 2 * b[i]. After applying those changes, the contribution of that index becomes min(a[i], 2 * b[i]). Return the maximum possible total contribution. Function Description Complete the function maximizeCappedContributionSum in the editor below. maximizeCappedContributionSum has the following parameters: Returns The source thread did not provide explicit numeric bounds.

Reported by candidates. Source: FastPrep

Pattern and pitfall

This is a greedy selection problem. For each index, calculate the gain from doubling: min(a[i], 2*b[i]) - min(a[i], b[i]). Sort all indices by gain in descending order and pick the top k. The math is straightforward once you see it, but the implementation needs care: you must consider all four cases (a[i] < b[i], a[i] >= 2*b[i], and the bands in between) to get the gain right. Most candidates either miscount the gain or greedily double in the wrong order. StealthCoder lets you paste a pre-validated solution if you hit a wall mid-OA, so you can move forward without losing composure.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Maximize Capped Contribution Sum 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. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

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. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximize Capped Contribution Sum FAQ

What's the key insight here?+

Calculate the gain (benefit) of doubling each b[i] before you choose. The gain is min(a[i], 2*b[i]) - min(a[i], b[i]). Sort by gain descending. Pick the top k. That's it. Most people either don't calculate gain correctly or forget that some doublings give zero gain.

How do I calculate the gain for a single index?+

Gain = min(a[i], 2*b[i]) - min(a[i], b[i]). If a[i] < b[i], gain is a[i] - min(a[i], 2*b[i]), which is a[i] - a[i] = 0 (no gain). If a[i] >= 2*b[i], gain is 2*b[i] - b[i] = b[i]. If b[i] <= a[i] < 2*b[i], gain is a[i] - b[i]. Compute all, sort, pick top k.

Can I use a heap or priority queue?+

Yes. Build a max-heap of (gain, index) tuples. Pop k times. Or just sort the gains array and take the top k indices. Sorting is simpler and fast enough for most test cases. Both are O(n log n), so either works.

What if two indices have the same gain?+

Doesn't matter. Pick either one. You're choosing k best gains. If there's a tie, the order doesn't change the final sum. Just be consistent in your sort order (e.g., stable sort or a tiebreaker by index).

How do I avoid off-by-one errors?+

After calculating gains for all n indices, sort descending. Take exactly min(k, n) indices (in case k > n). Sum the original contributions from unpicked indices, plus the doubled contributions from the top k indices. Walk through a small example by hand before submitting.

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