Reported September 2026
Amazontwo pointers

Container With Most Water

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

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

The brute force for Container With Most Water looks fine until n hits 10^5, and that's the mistake that sinks a first attempt. Amazon candidates reported this one in September 2026, and it's a clean two-pointer problem hiding behind a geometry story. You pick two lines, the shorter one caps the water, and width is the index gap. If you check every pair, you time out. If you know the pointer trick, you're done in ten lines. And if your brain freezes mid-assessment, StealthCoder runs invisibly as a safety net and hands you the approach in real time.

The problem

You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the i-th line are (i, 0) and (i, height[i]).
Find two lines that, together with the x-axis, form a container so that the container holds the most water.
Return the maximum amount of water a container can store.
You may not slant the container.

Function
maxArea(height: int[]) → int

Examples
Example 1
height = [1,8,6,2,5,4,8,3,7]
return = 49
The lines at indices 1 and 8 have heights 8 and 7. The width is 7, so the area is min(8, 7) * 7 = 49.
Example 2
height = [1,1]
return = 1
The only pair forms a container of width 1 and height 1.

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 area as min(height[l], height[r]) * (r - l) and update your max. Then move the pointer at the shorter line inward. Why that one? The shorter line limits the height, and shrinking the width can only help if you find a taller line. Moving the taller pointer can never improve the result, so you skip it safely. That gives O(n) time and O(1) space. The common pitfalls: moving the wrong pointer, using max instead of min for height, and forgetting width is r - l, not r - l + 1. Zero heights are fine, they just give zero area. Use a plain int, since 10^4 * 10^5 is 10^9 and fits in 32 bits. If you blank during the live OA, StealthCoder is the hedge that surfaces the two-pointer move while you stay in control of the keyboard.

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 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. 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

⏵ 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 Amazon's OA.

Amazon 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.

Container With Most Water FAQ

What's the trick for Container With Most Water?+

Two pointers from both ends. Compute the area, then move the pointer at the shorter line inward. The shorter line caps the height, so moving the taller one can't beat your current best. One pass, O(n) time, O(1) space.

Why does the brute force fail in the Amazon OA?+

Checking every pair is O(n^2). With n up to 10^5 that's around 5 billion pair checks, which will time out on the larger test cases. It passes the small examples, so you won't notice until hidden tests run.

Which pointer do I move when heights are equal?+

Either one works. If both lines are equal, any better container needs both ends to change anyway, so moving one is safe. Just pick left or right consistently and the loop still reaches the right answer.

How do I prepare for this in 48 hours?+

Write the two-pointer solution from memory twice. Then trace Example 1 by hand and explain why you skip the taller line. Also do a couple of related two-pointer problems so the pattern feels automatic under pressure.

Is this problem still being asked at Amazon?+

It was reported in September 2026, so yes, it's circulating. Expect small twists like different input framing, but the core task of maximizing min height times width stays the same.

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

OA at Amazon?
Invisible during screen share
Get it