#K79862. Move Zeroes
Move Zeroes
Move Zeroes
Given an array of integers, move all the zeros to the end while maintaining the relative order of the non-zero elements. This problem requires you to modify the array in-place with minimal operations.
For example, given an array [0, 1, 0, 3, 12]
, the expected output after moving zeros is [1, 3, 12, 0, 0]
.
Note: The input will be provided via standard input and the output should be written to standard output.
inputFormat
The first line contains an integer N (1 ≤ N ≤ 105), which is the number of elements in the array. The second line contains N space-separated integers representing the elements of the array.
outputFormat
Output a single line with the N integers of the modified array after moving all zeroes to the end. The numbers should be separated by a single space.
## sample5
0 1 0 3 12
1 3 12 0 0