Monk and Tasks
Practice
3.9 (196 votes)
Easy
Hash maps
Open
Problem
90% Success 26429 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Monk A loves to complete all his tasks just before the deadlines for introducing unwanted thrill in his life. But, there is another Monk D who hates this habit of Monk A and thinks it's risky.

To test Monk A, Monk D provided him tasks for N days in the form of an array Array, where the elements of the array represent the number of tasks.

The number of tasks performed by Monk A on the ith day is the number of ones in the binary representation of Arrayi.

Monk A is fed up of Monk D, so to irritate him even more, he decides to print the tasks provided in non-decreasing order of the tasks performed by him on each day. Help him out!

Input:
The first line of input contains an integer T, where T is the number of test cases.
The first line of each test case contains N, where N is the number of days.
The second line of each test case contains Array array having N elements, where Arrayi represents the number of tasks provided by Monk D to Monk A on ith day.

Output:
Print all the tasks provided to Monk A in the non-decreasing order of number of tasks performed by him.

Constraints:
1 <= T <= 100
1 <= N <= 105
1 <= Arrayi <= 1018

Note:
If two numbers have the same number of ones (set bits), print the one which came first in the input first, and then the other one, as in the input.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
5 votes
Tags:
Basic ProgrammingBit ManipulationBit manipulationEasy
Points:20
110 votes
Tags:
Basic ProgrammingBit manipulationEasy
Points:20
131 votes
Tags:
Bit manipulationEasyOpenSorting