We use cookies for site analytics. Accept to help us understand how the site is used. See our Privacy Policy for details.
Two pointers turn a nested loop into a single pass by exploiting order: move the left pointer to increase a sum, the right to decrease it, and never revisit. It shows up in pair-sum problems, palindrome checks, in-place array partitioning, and container/area questions. If the input is sorted and you are about to write two nested loops, stop and reach for this first.
A sorted input, a palindrome check, or a pair/triplet that must satisfy a condition.
24 problems. Each one runs in an in-browser editor against real test cases, with hints and a worked solution.
The patterns cheat sheet covers all of these in one page - what each one looks like in a problem statement, and the template that follows.