← Pointer Manipulation

Micro-Drill #269 — Reverse array in-place

Pointer Manipulation Target: 5s

Converging two pointers from both ends. The most basic symmetric array operation — used in reverse, palindrome check, etc.

l, r = 0, len(a) - 1
while l < r:
    a[l], a[r] = a[r], a[l]
    l += 1
    r -= 1

Type it from memory. Go.

Practice Problems

Related Coding Drills

← Micro #268 Micro #270 →