AAlgoLoopSpaced repetition for LeetCode

Two Pointers

The two-pointer technique walks two indices through a sequence — from both ends inward, or one ahead of the other — to solve a problem in a single pass and O(1) extra space. Reach for it on sorted arrays or strings when you're looking for a pair, a triplet, or a partition and a brute-force double loop would be O(n²).

24 LeetCode problems solved with the Two Pointers pattern. Practice them with spaced repetition so the pattern sticks.

See the full solution

The complete approach, reference solutions in 5 languages, and a step-by-step visualization — then add this problem to your spaced-repetition schedule.

Start free →