Cardinality Sorting

Problem Overview

  • Sort an integer array by ascending binary cardinality (count of 1s in binary), breaking ties by the decimal value.
  • Input: nums[n] with 1 ≤ n ≤ 10^5 and 1 ≤ nums[i] ≤ 10^6; Output: the sorted array.
  • Context: tests understanding of bitwise properties and custom sorting used in real-world data processing.
  • Source: Oracle interviews; a classic coding interview problem and interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: