CodeMentor.
Ask AIProblemsLearnC++TCSCore CSHRProgress
0Lv 1
ProblemsHashing

Top K Frequent Elements

Medium
LeetCode
4/8
MediumHashingLeetCode #347

Top K Frequent

Count → bucket by frequency (or heap). Interview favorite: bucket sort O(n).

Examples

Example 1

Input

6 2
1 1 1 2 2 3

Output

1 2
Example 2

Input

1 1
1

Output

1

Stuck? Take a nudge

C++17Autosaves