← Pointer Manipulation

Micro-Drill #6 — Reverse a segment

Pointer Manipulation Target: 10s

In-place segment reversal is the building block for rotate-array and next-permutation.

# Reverse a[l:r+1] in-place
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 #5 Micro #7 →