Given an array A[] of n elements filled with several integers, some of them being zeroes, write a program to move all the zeroes to the end.

Problem Note

  • The relative order of non-zero integers needs to remain the same as in original array.
  • You must do this in-place without making a copy of the array.
  • Minimize the total number of operations.

Example 1

Input: A[] = [1, 8, 0, 2, 0, 1, 13, 0]
Output: [1, 8, 2, 1, 13, 0, 0, 0]

Example 2

Input: A[] = [0, 0, 0, 23, 2]
Output: [23, 2, 0, 0, 0]