73. Move the Zeros to the End

Acceptance — 0 accepted 0 submissions

Easy
ArraysTwo Pointers
No companies listed
A shopkeeper's stock list has some items with 0 quantity. He wants all the out-of-stock (zero) items moved to the end, while the other items keep their original order.

Move all zeros to the end.

Input Format
The first line has n.
The second line has n integers.

Output Format
Print the modified array, separated by single spaces.

Constraints
• 1 ≤ n ≤ 1000
• -1000 ≤ value ≤ 1000

Example 1

Input
6
0 1 0 3 12 0
Output
1 3 12 0 0 0

Explanation Non-zero items 1, 3, 12 keep their order, and the zeros go to the end.

Example 2

Input
3
0 0 0
Output
0 0 0

Explanation All zeros, nothing to move.

Example 3

Input
4
5 -2 7 9
Output
5 -2 7 9

Explanation No zeros at all.

Acceptance —
Accepted 0
Submissions 0
Auto-save
Saved Ln 1, Col 1
Submit a solution to see its status here.
Input
Expected Output
1 3 12 0 0 0
No results yet
Run your code to test it against the sample cases.
Problem List