The Design A Leaderboard interview question asks you to build a system that tracks player scores. You need to support adding scores to existing players, resetting a player's score to zero (effectively removing them), and querying the sum of the top scores on the board. This Design A Leaderboard coding problem focuses on balancing the cost of individual updates against the cost of calculating global statistics.
Companies like Bloomberg and Amazon ask this to test your understanding of Sorting interview patterns and data organization. It evaluates whether you can identify that you don't always need a perfectly sorted list if you only need the "Top K" sum occasionally. It also tests your ability to handle sparse data (many players, few updates).
There are two main approaches:
Map<PlayerID, Score>. For top(K), collect all scores, sort them (), and sum the first .TreeMap<Score, Frequency> to store how many players have a specific score. This allows top(K) to be calculated by iterating through the scores in descending order ( or ).addScore(1, 50), addScore(2, 100), addScore(3, 20): Map: {1:50, 2:100, 3:20}.top(2):
[100, 50, 20].100 and 50. Sum = 150.reset(2): Map: {1:50, 3:20}.top(1): Returns 50.addScore is per update, which is inefficient if updates are frequent.Always ask the interviewer about the read/write ratio. If top(K) is called much less frequently than addScore, a simple Map + occasional sort is often the most practical and easiest solution to implement.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Frequency Tracker | Medium | Solve | |
| Design a Todo List | Medium | Solve | |
| Design a File Sharing System | Medium | Solve | |
| Tweet Counts Per Frequency | Medium | Solve | |
| Design In-Memory File System | Hard | Solve |