Stable Zeroing


Submit solution

Points: 20
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

Azuz, the scientific committee chair (has been doing nothing scientific anyway), started to learn how to code lately. He enjoyed the idea behind stable sorting and decided to make an interesting "stable zeroing" problem.

The idea behind stable zeroing is easy enough, you just need to move all the zeros to the end of the array, while leaving the non-zero elements in the same order they were before.

Your task is, giving an array, stable zero it!

Input Specification

The first line of the array contains an integer \(1 \le n \le 10^5\) denoting the size of the array. The second line of the input contains \(n\) integers, the elements of the array (the elements can be very large up to \(10^{18}\) and can be negative as well).

Output Specification

Output the resulting array after the transformation separated by 2 spaces.

Sample Input

3
1 0 2

Sample Output

1  2  0

Sample Input

5
1 0 2 0 3

Sample Output

1  2  3  0  0

Notes

The output should not have any space at the beginning or the end of the array.


Comments


  • 0
    AkramElOmrani  commented on July 28, 2021, 12:38 a.m. edit 2

    follow up : do this is O(1) space. It doesn't make much sense here since you can just count the number of zeros but concider a function that returns the array given with the zeros in the end in O(1) space try doing this problem


  • 0
    AkramElOmrani  commented on Jan. 13, 2021, 12:27 a.m.

    Than why they said that the numbers of the array can be up to 10^8


  • 0
    Jamesab123  commented on Aug. 30, 2020, 12:15 a.m. edit 3

    Hi! If we have a number that is composed of more than one digit, should we separate these digits or not? Like 3/1 55 403, the output should be 1 55 43 0 or 1 5 5 4 3 0?


    • 0
      aymanemoutei  commented on Aug. 30, 2020, 10:19 a.m.

      by definition , a digit is in an integer in the range [0;9] . And you're given only digits in the input .