= Two-pointer technique
= Two-pointer sweep
{synonym}
= Two-pointer
{synonym}
The <two-pointer technique> maintains two indices whose monotone movement avoids revisiting candidate pairs. To find two values summing to $t$ in an increasing <array>, start at its ends. If their sum is too small, move the left index right: every pair using the old left value is too small. If too large, move the right index left by the symmetric argument. Each step eliminates one index, so after sorting the scan takes $O(n)$ time. The correctness depends on sorted order; blindly applying the rule to unsorted inputs can discard a valid pair.
Back to article page