On a sorted array, finds two values that add up to a target using a pointer at each end — moving them inward based on whether the current sum is too small or too large.
Binary search requires sorted data — your array is sorted automatically before searching.
On a sorted array, finds two values that add up to a target using a pointer at each end — moving them inward based on whether the current sum is too small or too large.
Time complexity: O(n). Space complexity: O(1).
Core idea — With the array sorted, one pointer starts at the smallest value and one at the largest; their sum tells you exactly which pointer to move.
What each pass accomplishes — If the pair sums too low, the left pointer steps right to a bigger value; if too high, the right pointer steps left to a smaller one. Every step permanently rules out one element, so the two pointers meet after at most n steps.
Use the interactive visualizer above to run Two-Pointer Pair Sum on your own input and watch every comparison, swap, and operation animate step by step — pause, scrub, or replay at any speed.