Search for a command to run...
A chocolate factory packs chocolates into packets placed on a conveyor belt. The packets are represented by an array of N integers.
Each number represents a packet with chocolates.
If a packet is empty, it is represented by 0.
Your task is to move all empty packets (0s) to the end of the array while keeping the order of the other packets the same.
You are given:
An integer N (size of the array).
N integers representing the packets.
Return the final array after moving all 0s to the end.
Integer N — number of packets.
N integers representing the array elements.
Print the array after moving all 0s to the end.
Input
8
4 5 0 1 9 0 5 0Output
4 5 1 9 5 0 0 0Input
6
6 0 1 8 0 2Output
6 1 8 2 0 0Example 1
8,[4,5,0,1,9,0,5,0]4 5 1 9 5 0 0 0Example 2
6,[6,0,1,8,0,2]
6 1 8 2 0 0Example 3
4,[0,0,0,1]1 0 0 08,[4,5,0,1,9,0,5,0]
4 5 1 9 5 0 0 0