Back to problems

Top K Frequent Elements in Integer Array Efficiently

Algorithm · Snapchat · Medium

For a nonempty integer list, identify the k values that occur most often. Input: An integer array with n entries plus an integer k; return the k values with the highest occurrence counts. Output: An array made up of the k most commonly occurring integers. Note: You can rely on k being valid: $$1 \le k \le$$ the count of distinct values. The running time must improve on O(n log n), with n denoting the length of the array. What approach would be most efficient when k is very…

Checking your access…