← All questions
MediumCoding
Container With Most Water
Asked at
Oracle
Paytm
Slice
Truemeds
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
- 01Start with the widest possible container using the first and last lines.
- 02Compute area as width times the shorter of the two heights.
- 03Move the pointer at the shorter line because keeping it cannot improve area as width shrinks.
- 04Track the best area until the pointers meet.
Reference answer
Then expect these follow-ups
Why can keeping the shorter line never produce a better area after width decreases?
Tests: greedy proof
Does the same pointer rule work for trapping rain water? Why or why not?
Tests: pattern discrimination
Free to read · better with Enzo
Practice this out loud with Enzo
Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.
Next question