Top K Frequent Elements

Python Hard 3 views
Back to Questions

Problem Description

Read n integers and k. Output k elements with highest frequency. If tie, smaller number first. Output in order of frequency desc then number asc.

Input Format

First line n k. Second line n integers.

Output Format

One line of k numbers.

Sample Test Case

Input:
8 2 1 1 1 2 2 3 3 3
Output:
1 3

Constraints

1

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Prev