values, where a zero marks an empty slot. Before the report is printed, every empty slot has to move to the end of the list, while the non-zero values stay in the order they came in.
Return the resulting array. The rearranging can be done right inside values, without making a copy.
Try to do it in one pass with as few writes to the array as possible.values=[0, 7, 0, -2, 5] → [7, -2, 5, 0, 0]
The non-zero values 7, -2, 5 keep their order and move to the front, and both zeros go to the end: [7, -2, 5, 0, 0].
values=[3, 1, 4] → [3, 1, 4]
There are no zeros, so the array stays the same.
values=[0, 0, 9] → [9, 0, 0]
The 9 moves to the front: [9, 0, 0].
values=[0, 7, 0, -2, 5]
[7, -2, 5, 0, 0]
Run checks the first 3 tests in your browser. Submit checks all 37 tests on the server, hidden ones included.