DesignTheSystem/dev
MEDIUM Low-Level Design (LLD) 11 automated tests

Design Game Leaderboard (Low-Level Design)

Add points, show the top players and anyone's rank, with ties handled consistently. Focus: Ranking with ties, and keeping reads cheap.

DifficultyMEDIUM
Design focusRanking with ties, and keeping reads cheap
Automated grading3 public + 8 hidden tests (11 total)
Phase 2 follow-upThis week's leaderboard
LanguageTypeScript (OOP / Machine Coding)

Problem statement

Players gain points over time; their score is the sum.

Rankings are by score, highest first. Players with equal scores share a rank: a player's rank is 1 + the number of players with a strictly higher score. Lists of top players break ties by name, alphabetically.

Functional requirements

  • addScore(player, points) adds points (a new player starts at 0).
  • score(player) is 0 for unknown players. top(k) returns up to k { player, score } entries.
  • rank(player) throws for an unknown player. reset(player) removes the player entirely.

Required API & starter interface

Implement the TypeScript class interface below. You can add any helper classes, policies or strategies you need:

class Leaderboard {
  addScore(player: string, points: number): void {
    throw new Error("Not implemented");
  }

  score(player: string): number {
    throw new Error("Not implemented");
  }

  top(k: number): { player: string; score: number }[] {
    throw new Error("Not implemented");
  }

  rank(player: string): number {
    throw new Error("Not implemented");
  }

  reset(player: string): void {
    throw new Error("Not implemented");
  }
}

Public test cases

Your code runs against 3 public tests plus 8 hidden edge-case tests in a sandbox:

Top players (core)

var lb = new Leaderboard();
lb.addScore("ann", 50); lb.addScore("bob", 80); lb.addScore("cat", 20);
assertEqual(lb.top(2), [{ player: "bob", score: 80 }, { player: "ann", score: 50 }]);

Scores add up (core)

var lb = new Leaderboard();
lb.addScore("ann", 10); lb.addScore("ann", 15);
assertEqual(lb.score("ann"), 25);
assertEqual(lb.score("nobody"), 0);

Rank (core)

var lb = new Leaderboard();
lb.addScore("a", 10); lb.addScore("b", 30); lb.addScore("c", 20);
assertEqual(lb.rank("a"), 3);

Design & structure checks

Beyond passing tests, the grader inspects your class structure for clean object-oriented design:

  • The ordering rule (score, then name) is written once: top() and rank() must agree. One comparison function used by both keeps them consistent.

Phase 2: Change request

In real interviews, the follow-up tests whether your design is extensible. After your first version passes all 11 tests, you unlock the change request: This week's leaderboard.

Pair with High-Level System Design

Ready to scale Game Leaderboard across distributed servers? Try the matching HLD simulator problem: Design Real Time Leaderboard.

Relevant low-level design lessons

More low-level design problems