Three Sum
Fix one element, run two-sum on the rest; skip duplicates.
Decision · step 3 of 13Two Pointer Problems: Three sum to zero
-4 + -1 + 2 = -3, short of 0. Only a bigger left value can help, so left moves up.
What you will see
An anchor pointer walks; for each anchor the inner pair converges.
Cost
| Best | O(n^2) |
|---|---|
| Average | O(n^2) |
| Worst | O(n^2) |
| Space | O(1) |
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.
Screen readers: Pointers announce their name and index; each step announces which pointer moved and why.
Reduced motion: Pointers appear at their new index with a brief emphasis instead of gliding.
Before this
Taught by the same lesson
Two Pointer Problems covers these too, in the same run.