Your free access ends in 7 days — and you haven’t tried it yet. Watch one algorithm run, start to finish. It takes about two minutes.

Try one problem
0
Concept

Introduction

Opposite-ends two pointers
step 1 / 10
3
8
12
17
21
26
30
[0][1][2][3][4][5][6]
Concept
1left ← 0
2right ← n - 1
3while left < right:
4 inspect arr[left] and arr[right]
5 decide: move left++ or right--
6 (occasionally both)
7stop when leftright
state
  • n7

line 1A two-pointer walk uses just two indices. Most often: one at the start, one at the end.