Design A Leaderboard
Medium · Heap & Priority Queue · about 15 minutes
Asked at Bloomberg, Amazon, Pinterest, Uber, Google, Duolingo.
Design a game leaderboard.
Leaderboard()creates an empty board.addScore(playerId, score)addsscoreto the player's total (creating the player with that score if new).top(K)returns the sum of the topKplayers' scores.reset(playerId)sets the player's score back to 0 (removes them); the player exists when this is called.