Opposite ends
lo=0, hi=n-1. Move towards center. Used on sorted arrays. Problems: two sum sorted, container water, palindrome check.
Same direction
slow=0, fast=0. Fast advances first. Used for: remove duplicates, move zeros, partition arrays.
Two arrays
i=0, j=0. Each points into a different array. Used for: merge sorted arrays, compare versions, intersection.
Sorted array [1,2,7,11,15], target=9. Two pointers squeeze inward โ sum too large means move hi left, sum too small means move lo right.
๐ง Under the Hood โ why O(nยฒ) collapses to O(n)
Every comparison either moves lo right or hi left, and sorted order guarantees the discarded pairs could never be the answer. If the sum is too small, no pair using this lo works (hi is already the largest partner available) โ so an entire row of the candidate grid is eliminated in O(1). The pointers can move at most nโ1 times combined, which is the whole complexity proof.