FastPrepTop K Frequent Elements
Problems/Top K Frequent Elements

Top K Frequent Elements

Bloomberg LP logoBloomberg LP● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names this well-known problem directly in a Bloomberg campus-recruiting question bank. It notes that many questions may be changed slightly, but it does not say what changed here. We used the standard Top K Frequent Elements with a fixed output order. Our version is about 70% the same as the reported question.

You are given an integer array nums and an integer k. Return the k distinct values that occur most frequently.

The selected set is guaranteed to be unique. List the selected values by decreasing frequency; when two selected values have the same frequency, list the smaller value first.

Function

topKFrequent(nums: int[], k: int) → int[]

Examples

Example 1

nums = [1,1,1,2,2,3]k = 2return = [1,2]

The frequencies are three for 1, two for 2, and one for 3.

Example 2

nums = [4,4,-1,-1,2]k = 2return = [-1,4]

Both selected values occur twice, so the smaller value comes first.

Constraints

  • 1 <= nums.length <= 100000
  • -10000 <= nums[i] <= 10000
  • 1 <= k <= the number of distinct values in nums.
  • The set of k most frequent values is unique.

More Bloomberg LP Onsite Interview questions

  • Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Minimum Replacements to Make Two Strings AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEW
  • Top K Frequent ElementsCapgemini · ONSITE INTERVIEW
  • Top K Frequent Elements with Larger-Value Tie BreakOracle · ONSITE INTERVIEW
  • Top K Frequent ElementsInfosys · ONSITE INTERVIEW
  • Stable Top K Frequent WordsGoogle · PHONE SCREEN · ONSITE INTERVIEW
  • Rearrange Songs by AuthorZomato / Eternal · OA
  • Top K Frequent ElementsApple · PHONE SCREEN
  • Top K Frequent ElementsC3.ai · PHONE SCREEN
  • Smallest Range Covering Elements from K ListsSnap Inc. · PHONE SCREEN
See Bloomberg LP hiring insights
Saved
class Solution {
    public int[] topKFrequent(int[] nums, int k) {
        // Write your code here.
    }

}
Checking account…