Company: Intuit_8feb
Difficulty: medium
Bit Sorting Problem Description You are given an array of integers. Sort the array in descending order according to the number of set bits in their respective binary representations of the array elements. In binary representation of a number, a set bit is 1, and a clear bit is 0. Note: For integers having the same number of set bits in their binary representation, sort according to their position in the original array i.e. a stable sort. Input The first line of input contains an integer n, representing the size of the array. The second line of input contains n space-separated array elements. Output Print the sorted array on a single line. Numbers should be separated by space. Constraints 0 ≤ n ≤ 1000 Examples Example 1: Input: 3 5 2 3 Output: 5 3 2 Explanation: 2 has only one bit and is last, while the other two have two each. Among them, 5 occurred earlier than 3 and will be earlier in the result. Binary representations: 5: 101 3: 11 2: 10 Example 2: Input: 3 3 1 5 Output: 3 5 1