Medium · Sorting

Top K Frequent Elements

Given an integer array nums and an integer k, return the k values that occur most often in nums, in any order; the answer is guaranteed to be unique.

Examples

Example 1

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

Output: [1,2]

Example 2

[4,1,4,2,2,2], k=1

Output: [2]

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 Sorting problems