Pattern
Two Pointers
Use two pointers when the data is ordered, or when a pair of positions can close in from both ends. Each step moves one pointer and rules out many pairs at once. The usual cost is O(n) time after any sort, with O(1) extra memory.