Algomination
Data Structures
AboutContact

Algomination

Learn algorithms and data structures through smooth, interactive visualizations.

SortingSearchingArray AlgorithmsData StructuresAboutContact

© 2026Algomination. Created by Omang Rawat & Rahul Soni.

Omang Rawat
Rahul Soni
All array algorithms

Two-Pointer Pair Sum

Time O(n)Space O(1)

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.

1
2
3
4
6
8
9
11
Array sorted. Looking for two values that add up to 10.
Step 1 / 3
ComparingFound

About Two-Pointer Pair Sum

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).

How it works, step by step

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.