Top K Frequent Elements
Given an array of integers, find the K most frequently occurring elements.
Input format
The first line contains N and K. The second line contains N space-separated integers.
Output format
Print the K most frequent elements (ties broken by smaller value first).
Constraints
- Values fit in a 64-bit signed integer
- Trailing whitespace and a trailing newline are ignored by the judge
Read from stdin, write to stdout. Sample cases below show the exact format.
Sample cases
Example 1
Input
4 1
1 1 1 2Expected output
1Example 2
Input
5 2
1 1 1 2 2Expected output
1 2