AlgoScope

Reverse Array

Swap the outermost pair and step both pointers inward until they meet.

Array algorithms and techniques, algorithm, beginner
Both pointers reach index 3. The middle value stays where it is.70615243342516leftright
Both pointers reach index 3. The middle value stays where it is.70615243342516leftright

Two Pointers: Reverse in place

Step, step 7 of 8

The pointers meet on 4. The middle value never moves.

Cost

Best
O(n)
Average
O(n)
Worst
O(n)
Space
O(1)

Leads to

Topics that need this one first.

Taught by the same lesson

Two Pointers covers these too, in the same run.