Coding Challenge

Top K Frequent Elements

Medium
heaphashmapbucket-sort

Return the k most frequent elements.

Given an integer array and an integer k, return the k elements that appear most often.

Examples

Input: nums = [1,1,1,2,2,3], k = 2

Output: [1,2]

Constraints

  • 1 <= k <= number of unique elements

Preparing your coding workspace...