Segregate 0s and 1s
Submissions: 7907   Accuracy: 38.54%   Difficulty: Easy   Marks: 2

You are given an array of 0s and 1s in random order. Modify the array to segregate 0s on left side and 1s on right side of the array.

Input:
The first line of input contains an integer T denoting the number of test cases. For each test there will be two lines. The first line contains the size of the array N. The second line contains the N space seperated elements of the array.

Output:
Print the modified array.

Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 107
0 ≤ Ai ≤ 1

Example:
Input:
2
5
0 0 1 1 0
4
1 1 1 1

Output:
0 0 0 1 1
1 1 1 1

Explanation:
Testcase 1:
All 0s are segregated to left and all 1s to right of the array. So, the modified array is 0 0 0 1 1.

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

Author: rajatjha

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

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

to report an issue on this page.