Skip to content
DSA Visualizerpreview

Container with most water

Two walls hold the most water: move the shorter one inward, never the taller.

O(n) time · O(1) space

Values1, 8, 6, 2, 5, 4, 8, 3, 7

Each value is a wall's height. Start with the widest container: walls at 0 and 8.

Array of 9 values: 1, 8, 6, 2, 5, 4, 8, 3, 7. Active index 0 (1) and index 8 (7). Pointers l at index 0 and r at index 8.
  • compare
  • swap or write
  • settled

1 / 10

Speed

Space play · ← → step · Home End jump · drag the strip to scrub