Reported October 2025
Mastercardtwo pointers

Container With Most Water

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

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

The Mastercard OA reported in October 2025 is Container With Most Water, and it's a trap for anyone who reads it as a pair-search problem. It really reduces to one question: which pillar do you move inward? Get that right and it's a ten-line two-pointer loop. Get it wrong and you write an O(n^2) brute force that dies on 10^5 elements. You have an invite, not a lot of time, so here's the pattern. If your mind goes blank mid-assessment, StealthCoder runs invisibly on screen and gives you the solution in real time.

The problem

You are given an integer array height of length n. The i-th value represents a vertical pillar from (i, 0) to (i, height[i]).
Choose two pillars that, together with the x-axis, form a container. The water held by pillars at indices i and j is min(height[i], height[j]) * (j - i).
Return the maximum amount of water that any pair of pillars can hold. The container may not be slanted.

Function
maxArea(height: int[]) → int

Examples
Example 1
height = [1,8,6,2,5,4,8,3,7]
return = 49
The pillars at indices 1 and 8 have heights 8 and 7. Their width is 7, so they hold min(8, 7) * 7 = 49 units of water.
Example 2
height = [1,1]
return = 1
The only pair has width 1 and limiting height 1, so it holds 1 unit.
Example 3
height = [4,3,2,1,4]
return = 16
The first and last pillars have height 4 and are 4 units apart, so they hold 4 * 4 = 16 units.

Constraints
2 <= height.length <= 10^5.
0 <= height[i] <= 10^4.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Start with pointers at both ends. Compute min(height[l], height[r]) * (r - l) and update the best. Then move the pointer at the shorter pillar inward. Why: the width shrinks every step, so the only way to beat the current area is a taller limiting wall. Moving the taller pillar can't help, because the shorter one still caps the height while the width drops. Moving the shorter one at least gives a chance. That's the whole proof, and it's greedy. Common pitfalls: moving both pointers, using max instead of min, and forgetting heights can be 0. Equal heights are fine, move either one. Runtime is O(n), space O(1). Brute force over all pairs is 10^10 operations at the upper bound, so it fails. If you blank on the greedy argument during the live OA, StealthCoder is the safety net that surfaces the two-pointer solution.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Container With Most Water 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 by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as container with most water. If you have time before the OA, drill that.

⏵ The honest play

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

Mastercard reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Container With Most Water FAQ

How hard is Container With Most Water really?+

Medium on paper, easy once you know the trick. The code is tiny. The difficulty is justifying why you move the shorter pointer. If you can say that in one sentence, you've cleared the hard part of the Mastercard question.

What's the trick for this problem?+

Two pointers from both ends, always advance the one at the shorter pillar. Width only shrinks, so the shorter wall is the only thing worth replacing. Track the max area at every step and return it at the end.

Will brute force pass?+

No. With n up to 10^5, checking every pair is about 5 billion comparisons. It may pass tiny sample cases and then time out on the hidden ones. Go straight to the O(n) two-pointer approach.

What edge cases should I test?+

Test [1,1] for the minimum length, [4,3,2,1,4] where the outer pillars win, and arrays containing zeros. Also try a strictly increasing array and a strictly decreasing one. Equal-height ends should work whichever pointer you move.

How do I prepare in 48 hours?+

Write this solution from memory three times, then explain the greedy reasoning out loud. Next, do two or three other two-pointer problems like Two Sum II and 3Sum. That covers the pattern well enough for an OA like this one.

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

OA at Mastercard?
Invisible during screen share
Get it