Move All Zeros to the End
Easyjavapythonccppjavascript
Given an array of N non-negative integers, move every zero to the end while keeping the relative order of the non-zero elements unchanged.
Input Format
The first line contains an integer N. The second line contains N space-separated non-negative integers.
Output Format
Print the modified array as N space-separated integers on one line.
Example 1
Input
5 0 4 0 2 7
Output
4 2 7 0 0
Explanation: Non-zero elements keep their order; zeros are pushed to the end.
- 1 <= N <= 100000
- 0 <= A[i] <= 1000000000