Skip to interview prep
Apexed

11. Move Zeroes

EasyTwo pointers

Return nums with every 0 moved to the end while keeping the relative order of the non-zero elements. Try to do it in place.

Example 1

Input: nums = [0, 1, 0, 3, 12]
Output: [1, 3, 12, 0, 0]

Constraints

  • 1 ≤ nums.length ≤ 10⁴

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 4 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Move Zeroes — coding interview practice — Apexed