AlgoScope

Container With Most Water

AlgorithmintermediateTwo Pointers

Move the pointer at the shorter line inward; the taller one can never improve the area alone.

Decision · step 2 of 10Two Pointer Problems: Container with most water
active 1-8108162235445863778leftright1 < 7

Lines 1 and 7 are 8 apart, so they hold min(1, 7) x 8 = 8. New best. 1 is the shorter line and caps the depth, so only moving it can help. Left moves up.

Open in the player →or start at step 2

What you will see

Bars as heights; the area between the pointers is shaded; the shorter side moves.

How two pointer problems works →

Cost

BestO(n)
AverageO(n)
WorstO(n)
SpaceO(1)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.

Screen readers: Pointers announce their name and index; each step announces which pointer moved and why.

Reduced motion: Pointers appear at their new index with a brief emphasis instead of gliding.

Taught by the same lesson

Two Pointer Problems covers these too, in the same run.