Container With Most Water
Reported by candidates from Wayfair's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Strip away the water imagery and the Wayfair OA from September 2026 is asking one thing: pick two indices that maximize min(height) times distance. That's a two-pointer problem wearing a costume. With n up to 10^5, the brute force pair check is dead on arrival, so the assessment is really testing whether you know the shrink-inward trick. If you've seen it, it's ten lines. If you blank, StealthCoder is the invisible safety net running on your screen during the live OA. Either way, read the next section and walk in knowing the move.
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. Area is min(left, right) * (right - left). Now move the pointer at the shorter line inward. Why: the shorter line caps the height, and shrinking width can only hurt, so keeping the short line can never beat what you already recorded. Moving the taller one is pointless. Track the max as you go. That's O(n) time and O(1) space. Common pitfalls: moving the wrong pointer, using max instead of min for height, and off-by-one on width. Also watch zero heights, which just give area 0. Use a 64-bit-safe mindset, though 10^4 * 10^5 fits in a normal int. If the proof slips your mind under pressure, StealthCoder can surface the two-pointer solution during the live OA so you don't burn the clock on brute force.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
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 passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as container with most water. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Wayfair's OA.
Wayfair reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Container With Most Water FAQ
What's the trick to Container With Most Water?+
Two pointers at both ends, always move the one pointing at the shorter line. The shorter line limits the height, so any narrower container using it can't beat your current best. Update the max area each step and stop when the pointers meet.
How hard is this problem really?+
Medium on paper, easy once you know the pointer move. The brute force is obvious and fails on n = 10^5. The only real hurdle is justifying why you skip pairs. Once that clicks, the code is tiny and hard to get wrong.
Can I solve it with brute force for the Wayfair OA?+
It'll pass small examples but time out on large inputs since constraints go up to 10^5 elements. O(n^2) means roughly ten billion pair checks. Don't submit it as your final answer. Go straight to the O(n) two-pointer version.
What edge cases should I test?+
Test [1,1] which returns 1, arrays with zeros like [0,0,5], strictly increasing and strictly decreasing heights, and equal heights everywhere. Also check the minimum length of 2. Equal heights at both pointers is fine, move either one.
How do I prepare in 48 hours?+
Write the two-pointer solution from scratch twice without notes. Then explain aloud why moving the shorter side is safe. Skim related two-pointer problems like sorted two-sum and trapping rain water so the pattern feels familiar, then stop. Sleep matters more.