Two Pointers
Two indices, one pass: cut the pair-checking search space without missing an answer.
5 lessons · ~47 min · free
By the end you can
- Understand the elimination argument that lets two pointers skip most pairs safely
- Solve sorted pair-sum problems in one pass
- Rewrite arrays in place with a reader and a writer pointer
- Detect cycles with the fast and slow pointer trick
- Tell two-pointer problems apart from sliding window problems
Lessons
- 1A million pairs you never check8 minThe n² pair problem, and how sorted order lets two indices rule out almost all of it.
- 2Converging from both ends11 minPair sum on a sorted array, why moving the right pointer is always safe, and container-with-water.
- 3Reader and writer10 minSame-direction pointers that rewrite an array in place: dedupe, move zeroes, partition.
- 4Fast and slow pointers10 minFloyd's cycle detection: why a 2x pointer must lap a 1x pointer inside a loop.
- 5Spotting two-pointer problems8 minSorted input, in-place edits, pairs and palindromes: the cues, the traps, and the templates.
Practice it after
Real interview questions that test this pattern, in an editor with execution and AI feedback.