← Two Pointers · guided lesson

Two Pointers

1 / 17 · story

the story

Two pointers from both ends

Every tool here exists because something was too slow or broke without it. Here is what.

Folklore: nobody is credited with inventing it. Indices that start at both ends and walk towards each other already drive the partition step of Tony Hoare's Quicksort (1961), but the interview pattern grew out of everyday practice, not one paper.

why it matters: without it

Every sorted-pair question falls back to O(n²) pair checks, or to O(n) extra memory for a HashSet.

also in this chapter: Read / write pointers (in-place filtering) · Merging two sorted sequences (one pointer each) · Three-way partition (Dutch national flag)