⚡ AlgoZen_
~/home/two_pointers/two_pointers1 / 2

Two Pointers

Beginner

Place two pointers at opposite ends of a sorted array. Move them toward each other based on whether the current sum is too large or too small. Avoids the O(n²) brute-force.

time:O(n)
space:O(1)
⚡ +100_XP
step[1/5]
> Start
L
-2
-1
0
3
5
8
R
11
Sorted array. Find two numbers that sum to 6. Use L and R pointers starting at both ends.

// tap NEXT STEP to walk through one step at a time