Push every 0 in the integer array nums to the back of the array. The other numbers must stay in the same order they had before, packed together at the front.
Change nums itself and return nothing: don't build and hand back a second array. The judge reads nums after your function finishes, and that is the output shown in each example.
The non-zero values read 4, -2, 7, 5 both before and after. The three zeros fill the last three slots.
With no zeros to move, nums is left exactly as it was.
Constraints
1 <= nums.length <= 10⁴-2³¹ <= nums[i] <= 2³¹ - 1Think of it as keeping the non-zero values rather than moving the zeros: if they are packed to the front in their original order, the zeros are whatever is left over at the back.
The task talks about moving zeros, but the zeros are the easy part: every 0 looks the same, so nobody can tell which zero ended up where. What has to be right is the non-zero values. They must sit at the front, packed together, in the order they started in. Once that's true, every slot behind them simply holds a 0.
Time O(n)Space O(1)
The full walkthrough and code are part of Premium