#K16301. Move Zeroes

    ID: 24548 Type: Default 1000ms 256MiB

Move Zeroes

Move Zeroes

Given an array of integers, your task is to move all the zeroes to the end of the array while maintaining the relative order of the non-zero elements. This operation must be performed in-place.

Note: The challenge is to implement an algorithm that minimizes the number of operations using a two-pointer technique. Mathematically, for an array \(A\) of length \(n\), after processing, if \(A'\) represents the resulting array then:

\(A' = [a_1, a_2, \dots, a_k, 0, \dots, 0]\) where \(a_i \neq 0\) for \(1 \leq i \leq k\) and \(k = n - \text{number of zeroes in } A\).

inputFormat

The first line contains a single integer \(n\) denoting the number of elements in the array. The second line contains \(n\) space-separated integers representing the array.

outputFormat

Output a single line containing the modified array with all the zeroes moved to the end, preserving the order of the non-zero elements. Each element must be separated by a space.

## sample
5
0 1 0 3 12
1 3 12 0 0

</p>