Skip to content
Optimal Lab

DSA · interactive

Two pointers: the container with most water

Pick two lines to hold the most water. Checking every pair is O(n²). Start at both ends and always move the shorter line inward, and one pass is enough. Watch why.

Check 1 of 8

best 8

1L86254837R

Lines 0 and 8: min(1, 7) × 8 = 8. Move the left one, it's the shorter line.

Heights

8 checks vs 36 pairs
  1. 1

    The widest container uses the first and last line. Start there.

    L = 0, R = 8

  2. 2

  3. 3

  4. 4

  5. 5

In production

Tools and technologies

Two indices walking a sorted sequence is how merge joins and merge sort combine data.

Not tied to one language — use these names when you search docs or design a system.