visual walkthrough
Move Zeroes
Stable in-place partitioning with minimal writes.
The idea
Scan once with `read`. Each non-zero value is swapped into the slot at `write`, and `write` moves on. Zeros are never moved explicitly; they get pushed backwards by the swaps.
Non-zeros keep their original order, which is exactly what the problem asks for.
Complexity
| approach | time | space |
|---|---|---|
| Copy to a new array | O(n) | O(n) |
| Swap forward | O(n) | O(1) |