Container With Most Water
Given array of heights, find max water container area Area = min(height[i], height[j]) * (j - i) Example: [1,8,6,2,5,4,8,3,7] => 49
You're looking for two lines that hold the most water between them. The brute force checks every pair, but interviewers want to see you discover the two-pointer insight: start wide, then shrink inward by moving the shorter line. It's a beautiful example of greedy reasoning that comes up in many optimization problems.
Examples
You write
max_area(height: List[int])
Example 1
- Input
- [1,8,6,2,5,4,8,3,7]
- returns
- 49
Example 2
- Input
- [1,1]
- returns
- 1
The pattern behind it
Arrays & Hashing
I reach for it when
- You catch yourself scanning the array again for every element.
- The problem asks about duplicates, pairs, counts or groups.
Say this before you type. Say what the key is and what the value remembers, before you write the loop.
All 127 Arrays & Hashing problemsTwo Pointers
I reach for it when
- The array is sorted, or you can sort it.
- You need a pair, a triple or a palindrome.
Say this before you type. Say what each pointer means and what a move to the left or right rules out.
All 26 Two Pointers problems
Meet Coco
Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit. The editor and Run stay open without an account. Anyone can open the editor and run their code.
Each locked part opens in the editor once the part before it passes.
Prep guides that list this problem
Our company tags come from public interview write-ups. None of these is a confirmed question.