Move all zeroes to end of array
Submissions: 16023   Accuracy:

44.94%

  Difficulty: Easy   Marks: 2

Given an array A of positive integers. Push all the zero’s of a given array to the end of the array.

Input:
The first line contains an integer T denoting the total number of test cases. In each test cases, first line is number of elements in array N and next line contains array elements.

Output:
Print the array after shifting all 0's at the end.​

Constraints:
1 <= T <= 100
1 <= N <= 103
0 <= Ai <=103

Example:
Input:

1
5
3 5 0 0 4

Output:
3 5 4 0 0

Explanation:
Testcase 1: All the zeros are moved to last and then array is as shown in the output.

** For More Input/Output Examples Use 'Expected Output' option **

Author: Karan Grover


Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.