Company: oracle_29oct
Difficulty: medium
Ascending Binary Sorting Problem Description Rearrange an integer array according to the following rules: Sort the integers in ascending order by the number of 1's in their binary representations. If multiple integers have the same number of 1's, sort them by their decimal values. Example Illustration: elements = [7, 8, 6, 5] Binary representations: [0111, 1000, 0110, 0101] Grouped by number of 1's: [[1000], [0101, 0110], [0111]] After sorting by decimal value within groups: [8, 5, 6, 7] Function Description Complete the function rearrange in the editor with the following parameter(s): int elements[n]: an array of integers to sort Returns int[n]: an array of decimal integers sorted per the rules vector<int> rearrange(vector<int> elements) { // Function implementation } Examples Example 1: Input: elements = [1, 2, 3] Output: [1, 2, 3] Explanation: (1)10 -> (1)2 (2)10 -> (10)2 (3)10 -> (11)2 The decimal integers 1 and 2 both have one 1 in their binary representation, so they