1.Opposite-direction pointers (start/end converging)
Two pointers start at the two ends of a sorted array or string and move toward each other, comparing or combining the elements they point at — reversing, checking a palindrome, or finding a pair with a target sum, all in one O(n) pass.
Key features
- Runs in O(n) time and O(1) extra space — no second array or reversed copy needed
- Needs O(1) access to both ends — arrays, strings, and doubly linked lists qualify; a plain singly linked list cannot jump to its last element, so this pattern does not apply there directly
- On a SORTED array: sum too small → move left inward (a bigger value); sum too big → move right inward (a smaller value)
On a sorted array: sum too small, move left inward; sum too big, move right inward — swapping that rule breaks the search entirely.