Problem, as an interviewer would state it:
"Implement moveZeroes(arr) — moving every 0 in the array to the END, while preserving the relative order of all non-zero elements, mutating the array IN PLACE (no new array allocated)."
Examples:
moveZeroes([0,1,0,3,12]); // [1,3,12,0,0]
Clarifying questions expected:
- Does this genuinely need to mutate the array IN PLACE, or would returning a new array be acceptable?
- Should the RELATIVE order of the non-zero elements be preserved (a stable operation), or is any final order of non-zero elements acceptable?
- Should a genuinely negative zero (
-0) be treated the same as a plain0?
Code / implementation expected: Yes — real, direct proof of in-place mutation (via a same-reference check), plus confirmation the relative order of non-zero elements is genuinely, stably preserved.