Medium · Hash Maps

Find top K frequent elements

Given an integer array a and an integer k, return the k values that occur most often in a, in any order.

Examples

Example 1

[1,1,1,2,2,3], k=2

Output: [1, 2]

Example 2

[4,4,5,5,5,6], k=2

Output: [5, 4]

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Hash Maps problems