1244. Design A Leaderboard
Design a Leaderboard class that supports:
addScore(playerId, score): Update the score for a player by addingscoreto their existing score (or create new entry with score if player doesn't exist).top(k): Return the sum of the topkscores across all players.reset(playerId): Reset the score of the specified player to 0.
Examples
Input: [["Leaderboard","addScore","addScore","addScore","top","reset","top"],[[],[1,1],[2,2],[3,3],[3],[1],[3]]]
Output: [null,null,null,null,6,null,5]
Input: [["Leaderboard","addScore","addScore","addScore","addScore","top","reset","top"],[[],[1,2],[2,4],[3,6],[4,8],[3],[1],[3]]]
Output: [null,null,null,null,null,18,null,18]
Hints
Use a hash map to store player scores.
For top(k), maintain a sorted structure or use a priority queue.
Consider using a balanced BST or sorting scores when needed.
Related Problems
1244. Design A Leaderboard
Design a `Leaderboard` class that supports: