Container With Most Water
LeetCode 11 • Medium • Two Pointers
Find two lines that form the container holding the most water. Area = width × min(h[left], h[right]). Move the shorter pointer.
TimeO(n)single pass
SpaceO(1)two pointers
Left: —
Right: —
Max: —
Left
Right
Water
Left
—
Right
—
Max
0
Ready
Press Play. Two pointers at both ends. Area = width × min(h[left], h[right]). Move the shorter pointer inward.