Company: User Submitted
Difficulty: medium
[{"title": "Cardinality Sort", "problem_statement": " The binary cardinality of a number is the count of 1's in its binary representation. For example, the decimal number 10 corresponds to the binary number 1010, which has a binary cardinality of 2 because it contains two 1's. Given an array of decimal integers, sort it by: Increasing binary cardinality (primary criterion) Increasing decimal value (secondary criterion, when cardinalities are equal) Return the sorted array. Example n = 4\nnums = [1, 2, 3, 4] 1 10 → 1 2 , so 1's binary cardinality is 1. 2 10 → 10 2 , so 2's binary cardinality is 1. 3 10 → 11 2 , so 3's binary cardinality is 2. 4 10 → 100 2 , so 4's binary cardinality is 1. The sorted elements with binary cardinality of 1 are [1, 2, 4]. The array to return is [1, 2, 4, 3]. Function Description Complete the function cardinalitySort in the editor with the following parameter(s): INTEGER_ARRAY nums : an array of integers Returns INTEGER_ARRAY : the sorted