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) adds score to the player's total (creating the player with that score if new).
  • top(K) returns the sum of the top K players' scores.
  • reset(playerId) sets the player's score back to 0 (removes them); the player exists when this is called.

Related guides