Container With Most Water
A medium-tier problem at 58% community acceptance, tagged with Array, Two Pointers, Greedy. Reported in interviews at HSBC and 51 others.
Container With Most Water is a medium-difficulty array problem that appears in interviews at HSBC, SAP, Flipkart, and 49 other companies. The acceptance rate hovers around 58%, which sounds reasonable until you realize most people solve it the slow way first. You're given an array of heights and need to find two lines that form a container holding the most water. The naive brute force is O(n^2). The real solution is O(n) and hinges on a two-pointer greedy move that contradicts intuition. If you hit this live and blank on the greedy insight, StealthCoder surfaces the working solution invisible to the proctor.
Companies that ask "Container With Most Water"
Container With Most Water is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage.
Get StealthCoderThe trick is that you don't need to check every pair. Start with pointers at both ends, then move the pointer at the shorter height inward each iteration. This works because moving the taller pointer inward can only decrease area (width shrinks and height is capped by the shorter line). Moving the shorter pointer gives you a chance to find a taller line that might compensate for lost width. Most candidates overthink this as a DP or sliding-window search problem. It's pure greedy logic. The Array, Two Pointers, and Greedy topics all converge here. This problem teaches the pattern of eliminating impossible search space rather than exploring it. StealthCoder is the safety net if the greedy principle doesn't click during your live assessment.
Pattern tags
You know the problem.
Make sure you actually pass it.
Container With Most Water recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Container With Most Water interview FAQ
Is this problem still asked at big tech companies?+
Yes. It appears in interviews at 52 reported companies including SAP, HSBC, and Flipkart. It's a classic two-pointer problem that hiring teams use to filter candidates who can recognize greedy patterns. Frequency is solid.
Why does moving the shorter pointer inward always work?+
Because area is width times min(height). If you move the taller pointer, width shrinks and the limiting height stays the same or shrinks. Moving the shorter pointer is your only chance to increase the limiting height enough to offset lost width. It eliminates all pairs you'd never want to check.
What's the gotcha candidates miss?+
Assuming you need to check all n^2 pairs or that you can use a different greedy rule (like always moving the pointer at the smaller index). The counterintuitive part is that moving inward from full width is better than expanding outward, and the shorter height is what drives movement.
How does this relate to the Two Pointers topic?+
Two Pointers is a broad technique for linear traversal with constraints. This problem is the canonical greedy Two Pointers case. You use opposing pointers to shrink the search space intelligently rather than brute-force. It teaches you when Two Pointers can replace nested loops.
If I only studied this for 10 minutes, what do I need to remember?+
Start at both ends. Each step, move the pointer pointing to the shorter height inward. Track max area as you go. Done in one pass. Memorizing this pattern is faster than rederiving the greedy logic under interview pressure.
Want the actual problem statement? View "Container With Most Water" on LeetCode →