Tap here to switch tabs
Problem
Submissions

Problem: Top K Frequent Elements

Top K Frequent Elements gives you an integer array and a number k. Return the k distinct values that occur most often, in any order; the answer is guaranteed to be unique.

Statement

Given an array of integers, arr, and an integer, k, return the kk most frequent elements.

Note: You can return the answer in any order.

Constraints:

  • 11 ≤\leq arr.length ≤\leq 10310^{3}
  • 10−410^{-4} ≤\leq arr[i] ≤\leq 10410^{4}
  • 1 ≤\leq k ≤\leq number of unique elements in an array.
  • It is guaranteed that the answer is unique.
⋮
Tap here to switch tabs
Problem
Submissions

Problem: Top K Frequent Elements

Top K Frequent Elements gives you an integer array and a number k. Return the k distinct values that occur most often, in any order; the answer is guaranteed to be unique.

Statement

Given an array of integers, arr, and an integer, k, return the kk most frequent elements.

Note: You can return the answer in any order.

Constraints:

  • 11 ≤\leq arr.length ≤\leq 10310^{3}
  • 10−410^{-4} ≤\leq arr[i] ≤\leq 10410^{4}
  • 1 ≤\leq k ≤\leq number of unique elements in an array.
  • It is guaranteed that the answer is unique.