Top K Frequent Elements

00:00
MediumArrayHashMapHeapBucket Sort
AmazonFacebook

Find the k most frequent elements in an array. Return them in any order.

Examples

Input → nums=[1,1,1,2,2,3], k=2
Output → [1,2]
Input → nums=[1], k=1
Output → [1]
Input → nums=[4,1,2,4,2,1,1], k=2
Output → [1,4]