← Two Pointers

Pattern Recognition Drill

#123 — Container With Most Water

Medium Two Pointers

The Problem

Given n vertical lines, find two that form a container holding the most water.

What approach would you use?

Think about it before scrolling down.

Key Signals

Two Pointers

Start at widest. Move the shorter line inward (can't do better keeping it). O(n).

Alt: Greedy

Same logic. Moving the taller line can only decrease width without guaranteeing height increase.

Common Trap

Don't try all O(n²) pairs. The greedy proof: moving the taller side can never improve area.

← #122