Design a Leaderboard
Updated
Problem statement
Given a list of operations on a game leaderboard, return one integer for each TOP operation, in the order those operations appear. The scores start empty.
["ADD", playerId, score]addsscoreto that player's total. A player who is not there yet is created first.["TOP", k]asks for the sum of thekhighest current player totals.["RESET", playerId]removes that player's current score from the leaderboard.
Function
leaderboard(operations: String[][]) → int[]Examples
Example 1
operations = [["ADD","1","73"],["ADD","2","56"],["ADD","3","39"],["ADD","4","51"],["ADD","5","4"],["TOP","1"],["RESET","1"],["RESET","2"],["ADD","2","51"],["TOP","3"]]return = [73,141]The first TOP returns 73, the single highest total. After both resets and player 2's new score, the top three totals are 51, 51, and 39, so the second TOP returns their sum.
Example 2
operations = [["ADD","1","10"],["ADD","2","20"],["ADD","1","15"],["TOP","2"]]return = [45]Player 1 ends with 25 after both adds, and player 2 has 20. TOP asks for both players, so it returns their sum.
Example 3
operations = [["ADD","7","8"],["TOP","1"],["RESET","7"],["ADD","7","3"],["TOP","1"]]return = [8,3]The first TOP returns the only score added so far. RESET removes it, so the later ADD starts a new total, and the second TOP returns just that new score.
Constraints
1 <= operations.length <= 100000.1 <= playerId <= 100000.1 <= score <= 100000.- ADD totals and TOP sums fit in signed 32-bit integers.
- RESET references a player currently on the leaderboard.
1 <= k <=the current number of players for every TOP.- At least one TOP operation is present.
More Bloomberg LP Onsite Interview 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
- 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
Similar questions at other companies
- Worst-Performing Ads by CTR in a Campaign TreeUber · PHONE SCREENUber interview questions
- Streaming Top K Frequent ElementsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Progressive Banking SystemAirbnb · OAAirbnb interview questions
- Cloud Compute Credits SystemCoinbase · OACoinbase interview questions
- Recipe Rating ServiceNubank · PHONE SCREEN
- Fixed Window Average and ModeNuro · PHONE SCREENNuro interview questions
- Paged KV Cache AccessNVIDIA · PHONE SCREENNVIDIA interview questions
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Balanced Session ManagerPalantir · PHONE SCREENPalantir 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)