Animation10 min

Pointers Converging

Watch the search space shrink one decision at a time.

This animation runs the opposite-end squeeze on a sorted array, drawn as bars with a blue chevron (left pointer) and an orange chevron (right pointer) beneath it. Each step highlights the pair being touched, shows their sum in a pill above, and slides the losing pointer one cell inward with a caption explaining the decision — "sum too small → move left" or "sum too big → move right." Cells the pointers pass are grayed out: eliminated, never to be reconsidered.

What to watch for:

  • Elimination, not iteration. Every gray cell represents a whole family of pairs ruled out by one comparison. That's the compression that turns O(n^2) pair-checking into a single O(n) squeeze.
  • The decision is forced by sortedness. "Too small" can only be fixed by a bigger left value; "too big" only by a smaller right value. On unsorted bars, neither claim would hold — watch how every caption leans on the sorted order.
  • The pointers never cross. The loop ends when they meet; a valid pair needs two distinct indices.

Then switch to "you drive" mode: the sum appears and you pick which pointer moves. If you can go five-for-five with the reasons said out loud, you own this pattern.