← 返回 oracle 的题目列表Top K Frequent Elements with Descending Value Tie-Break
类型:online_judge
Given an integer array nums and an integer k, return the k distinct elements with the highest frequencies.
Ordering rules:
Higher frequency comes first.
If two elements have the same frequency, the larger numeric value comes first.
Return the result in this order.
Input Format
First line: two integers n k
Second line: n integers representing nums
Output Format
Print k integers separated by spaces.
Constraints
1 <= n <= 2 * 10^5
1 <= k <= number of distinct elements
-10^9 <= nums[i] <= 10^9
Example
Input
7 2
1 1 1 2 2 3 3
Output
1 3