← Pointer Manipulation

Micro-Drill #126 — Remove duplicates in-place

Pointer Manipulation Target: 10s

Write-pointer compaction for sorted arrays. Returns new length.

w = 1
for i in range(1, len(a)):
    if a[i] != a[i-1]:
        a[w] = a[i]
        w += 1
return w

Type it from memory. Go.

Practice Problems

Related Coding Drills

← Micro #125 Micro #127 →