FastPrepDynamic Top K Frequent Elements
Problems/Dynamic Top K Frequent Elements

Dynamic Top K Frequent Elements

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Bloomberg new grad phone screen. The report asks for inserting, deleting, and asking for the current top k by frequency. It talks about a HashMap with a min-heap, and about follow-ups at large scale. We added a finite way to write operations, a fixed order for ties, the rules for a valid delete, and the input limits. Our version is about 93% the same as the reported question.

Given operations, apply them in order to a multiset of integers and return the answer to each top-k request, in request order. A multiset is a collection where the same value can appear more than once. It starts empty.

  • [1, value] inserts one occurrence of value.
  • [2, value] deletes one occurrence of value. Every delete is valid when it happens.
  • [3, k] asks for the current k most frequent distinct values.

Rank values by how often they appear, most often first. If two values appear equally often, the smaller value comes first.

Function

dynamicTopK(operations: int[][]) → int[][]

Examples

Example 1

operations = [[1,5],[1,3],[1,5],[1,2],[1,3],[3,2],[2,3],[3,2]]return = [[3,5],[5,2]]

At the first query, 3 and 5 both appear 2 times, so the smaller value comes first. After one 3 is deleted, 5 still appears 2 times. Values 2 and 3 each appear 1 time, so 2 takes second place.

Example 2

operations = [[1,-1],[1,4],[1,-1],[2,-1],[3,2]]return = [[-1,4]]

After one deletion, both remaining values appear 1 time. They tie, so the smaller value, -1, comes before 4.

Example 3

operations = [[1,7],[1,7],[1,8],[2,7],[2,7],[3,1]]return = [[8]]

Both occurrences of 7 are removed, so only 8 remains when the query is processed.

Constraints

  • 1 <= operations.length <= 100000.
  • Every row of operations has exactly two integers.
  • Operation codes are 1, 2, or 3.
  • Inserted and deleted values are between -10^9 and 10^9.
  • Every delete names a value whose current frequency is positive.
  • Every top-k request satisfies 1 <= k <= the number of currently distinct values.

More Bloomberg LP Phone Screen questions

  • Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • 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
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
  • Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
  • Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Fixed Window Average and ModeNuro · PHONE SCREENNuro interview questions
  • Paged KV Cache AccessNVIDIA · PHONE SCREENNVIDIA interview questions
  • Balanced Session ManagerPalantir · PHONE SCREENPalantir interview questions
  • Worst-Performing Ads by CTR in a Campaign TreeUber · PHONE SCREENUber interview questions
  • Design Authentication ManagerOracle · ONSITE INTERVIEWOracle interview questions
  • In-Memory Priority Task SchedulerRippling · PHONE SCREENRippling interview questions
  • Design a Food Rating SystemApple · PHONE SCREENApple interview questions
  • Key-Value Store on a Block DeviceLambda · PHONE SCREEN
  • Lowest-Bid Auction SystemGoogle · ONSITE INTERVIEWGoogle interview questions
  • Rank-Based Cache with a Data SourceLinkedIn · PHONE SCREENLinkedIn interview questions

Bloomberg LP interview experiences

  • Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
  • Bloomberg SWE Intern Interview Questions: 68 Questions
  • Bloomberg Interview Questions, Level Not Reported: 65 Questions
  • Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
  • Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
  • Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public int[][] dynamicTopK(int[][] operations) {
        // Write your code here.
    }

}
Checking account…