Back to DSA

Top K Frequent Elements

medium
Acceptance: 50%
HeapHash TableSorting

Given an array of integers and an integer k, identify the k elements that appear most frequently. The result may be returned in any order.

Examples

Example 1:
Input:nums = [3,3,3,1,1,2], k = 2
Output:[3,1]
Example 2:
Input:nums = [7], k = 1
Output:[7]

Hints

00:00
1234567