Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Silent Caravan

Learn
Play
Prove
Lesson 1 of 5

Live algorithm trace

Stable in-place compaction

Complete execution
1 of 9

Write marks the next position for a non-zero value.

1write = 0
2scan each x from left to right
3if x != 0: nums[write] = x; write += 1
4while write < length: nums[write] = 0; write += 1
5return nums
write = 0

A sandstorm scattered empty carts (0) through the caravan. Move every loaded cart forward while keeping their order in place, with no second caravan.

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead