Skip to main content
LeetCode 1244, Medium. Topics: Design, Hash Table, Sorting. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 15 parametrized pytest cases, and a playground notebook:

Problem

Design a Leaderboard class, which has 3 functions:
  • addScore(playerId, score): Update the leaderboard by adding score to the given player’s score. If there is no player with such id in the leaderboard, add him to the leaderboard with the given score.
  • top(K): Return the score sum of the top K players.
  • reset(playerId): Reset the score of the player with the given id to 0 (in other words erase it from the leaderboard). It is guaranteed that the player was added to the leaderboard before calling this function.
Initially, the leaderboard is empty.

Examples

Constraints

  • 1 <= playerId, K <= 10^4
  • It’s guaranteed that K is less than or equal to the current number of players.
  • 1 <= score <= 100
  • At most 1000 function calls will be made.

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026