DSA · Reimagined
Arrays easy time O(n) space O(1)

Move Zeroes

Keep a write pointer for the next non-zero slot. Scan the array; each non-zero value swaps down to that slot. Zeros naturally collect at the back, order preserved.

0
0
1
1
0
2
3
3
12
4
0
5
5
6
w

Write pointer w marks the next slot for a non-zero value.

1 / 9

Practice

Machine twin: /dsa-viz-v2/move-zeroes.json — the full deterministic run as structured data.