Two Pointers

Coordinate two moving indices to scan, compare, or compress search space efficiently.

Coordinate two moving indices to scan, compare, or compress search space efficiently.

All pairs outside the current [left, right] window have already been proven impossible.

Because the array is sorted, moving the left pointer right increases the sum, and moving the right pointer left decreases the sum.

This lets us eliminate impossible pairs without checking all combinations, shrinking the search space efficiently.