Two-Pointer Technique
The Two-Pointer technique uses two indexes that move through a data structure according to the problem's constraints. It is especially effective for sorted arrays, partitioning problems, and string comparisons.
A classic use case is Two Sum in a sorted array.
The technique can reduce an O(n²) brute-force search to O(n).
It is also useful for palindrome validation and array partitioning.
Correct pointer movement depends on an invariant, such as sorted order.