← Pointer Manipulation

Micro-Drill #87 — Move zeros to end

Pointer Manipulation Target: 10s

Move-zeroes is remove-element followed by a fill. Classic two-pointer warm-up.

w = 0
for r in range(len(a)):
    if a[r] != 0:
        a[w] = a[r]
        w += 1
while w < len(a):
    a[w] = 0
    w += 1

Type it from memory. Go.

Practice Problems

Related Coding Drills

← Micro #86 Micro #88 →