Mid
Detailed answer
Two Pointers
DSA & Coding Interviews
Explain Container With Most Water.
Short answer: Two pointers at both ends. Area = min(height[L], height[R]) * (R − L). Move the pointer at the shorter line inward, because width shrinks and only a taller line can improve area. O(n) time.
Complexity
Time O(n), Space O(1).
Edge cases to mention
- Length 2
- Strictly increasing heights
Common follow-ups
- Trapping Rain Water (harder, needs prefix max or stack)
Prove the greedy move: the shorter side is the bottleneck.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png