Binary Array Sorting
Posted: 25 Dec, 2020
A binary array is an array consisting of only 0s and 1s.
You are given a binary array "arr" of size ‘N’. Your task is to sort the given array and return this array after sorting.
Input Format :
The first line of input contains an integer ‘T’ denoting the number of test cases. The next ‘2*T’ lines represent the ‘T’ test cases. The first line of each test case contains an integer ‘N' denoting the size of the array. The second line of each test case contains ‘N’ space-separated integers consisting of 0s and 1s as the array elements.
Output Format :
For each test case, print ‘N’ space-separated integers representing the elements of the sorted binary array in a separate line. Print the output of each test case in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
Follow Up :
1. Can you solve this problem in a linear time and constant space? 2. Can you solve this problem in a single traversal only?
1 <= T <= 50 1 <= N <= 10^4 0 <= arr[i] <= 1 Where ‘T’ is the number of test cases and ‘N’ is the size of the array. Time Limit: 1 sec
Best time to buy and sell stock
Posted: 2 Sep, 2022
Best time to buy and sell stock II
Posted: 5 Sep, 2022
Posted: 21 Oct, 2022
Find The Single Element
Posted: 30 Oct, 2022
Posted: 24 Nov, 2022