Order by Set Bits
Sort the values by the number of 1-bits in their binary form; break ties by the value itself (ascending).
Input: the first line has N; the second line has N integers.
Output: the values in the required order.
Constraints:
- 1 ≤ N ≤ 105
- 0 ≤ ai ≤ 109
Sample Tests
Input 1
5 12 5 30 7 19
Output 1
5 12 7 19 30
Input 2
2 100 2
Output 2
2 100
Discussion (opens after you solve — no spoilers before)
No comments yet.