DSAverse
Two Pointers & Sliding Window
Loading Two Pointers...
Two Sum Pattern
2 + 6 = 82
7
11
15
1
8
3
9
4
6
L=0target: 10R=9
Initializing Sorting Algorithms...
Sorting
Trees
Graphs
Preparing interactive visualizations...
Two Pointers & Sliding Window
Loading Two Pointers...
Two Sum Pattern
2 + 6 = 8Use two pointers starting at opposite ends of a sorted array. Converge inward based on whether the current sum is too small or too large — O(n) time, O(1) space.
Ready — press Play or step through.
Question 1 of 3
Why does this two-pointer approach work on a sorted array but not on an unsorted one?