Problem of the day
1. If any two numbers have the same count of set bits, then in the sorted array they will appear in the order in which they appear in the original array. For example, let the array be { 2, 4, 3}, in this case, both 2 and 4 have the same number of set bits so the answer will be {3, 2, 4} and not {3, 4, 2}, because in the original array 2 appears before 4.
2. The array may contain duplicate elements.
The first line of input contains the integer T, denoting the number of 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 denoting the array elements.
The only line of output of each test case consists of N space-separated integers, the elements of the array in the order as described in the problem statement
You do not need to print anything, it has already been taken care of. Just implement the given function. Also, you need to modify the given array in-place.
1 <= T <= 50
1 <= N <= 10^4
1 <= arr[i] <= 10^9
1
3
2 4 8
2 4 8
The binary representation of 2,4 and 8 will be {10, 100, 1000}, respectively. The count of set bits is one for all the three numbers so the sorted order will be {2, 4, 8}.
1
3
4 3 8
3 4 8
The binary representation of 3,4 and 8 will be {11, 100, 1000}, respectively. The count of set bits for 3,4, and 8 is 2,1 and 1 respectively. So the sorted order will be {3, 4, 8}.