The Zero Migrator
MediumAcc. 89.4%
+30 XP 12
Resource Compaction
In memory management, we often move "empty" slots (zeros) to the end of a block.
The Assignment
Your function receives an array data.
- Iterate through the array and print all non-zero numbers first.
- Count how many zeros were in the array.
- Print that many zeros afterward.
- Each number should be on a new line.
01EXAMPLE 1
Input
[0, 1, 0, 3, 12]Output
1
3
12
0
0Explanation: Non-zeros first, then trailing zeros.
Constraints
- Relative order of non-zeros must be preserved.
ArraysLoops
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
data[0,1,0,3,12]
Expected Output
1 3 12 0 0
Click RUN to test your solution