AAlgoLab
ALG-M013MediumHashing

Most Common Signal Codes

Return the k distinct values with highest frequency. Order by descending frequency, then by ascending numeric value for ties.

Contract

input numbers: integer[]
input k: integer
return integer[]

Constraints

  • • 1 <= k <= count of distinct numbers
  • • 1 <= length <= 100000

Examples

Example 1
numbers = [1, 1, 1, 2, 2, 3]
k = 2
→ [1, 2]
Example 2
numbers = [4, 4, 3, 3, 2]
k = 2
→ [3, 4]

5 judge tests (2 shown above). Target complexity: O(n log n) acceptable.