DesignTheSystem/dev
EASY Low-Level Design (LLD) 12 automated tests

Design Snake and Ladder (Low-Level Design)

A board game where the board, the players and the rules for a turn are separate pieces. Focus: Separating the board, the players and the turn rules.

DifficultyEASY
Design focusSeparating the board, the players and the turn rules
Automated grading3 public + 9 hidden tests (12 total)
Phase 2 follow-upSixes
LanguageTypeScript (OOP / Machine Coding)

Problem statement

Squares run from 1 to `size`. All players start at 0, off the board, and take turns in the order given.

A roll moves the player forward. If that would pass `size`, the player stays put. Landing on a snake's head moves the player down to its tail; landing at the bottom of a ladder moves them up to its top (one jump only).

The first player to land exactly on `size` wins and the game ends.

Functional requirements

  • new SnakeAndLadder(size, snakes, ladders, players): snakes map head → tail (head above tail), ladders map bottom → top (top above bottom). Heads, tails and ladder bottoms are in 1..size-1; a ladder may end on size. Invalid boards throw.
  • move(roll) plays the current player's turn and returns { player, from, to, won }. Rolls must be whole numbers 1 to 6. Moving after the game ended throws.
  • position(player), currentPlayer(), winner() (or null).

Required API & starter interface

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

class SnakeAndLadder {
  constructor(
    size: number,
    snakes: Record<number, number>,
    ladders: Record<number, number>,
    players: string[]
  ) {}

  move(roll: number): { player: string; from: number; to: number; won: boolean } {
    throw new Error("Not implemented");
  }

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

  currentPlayer(): string {
    throw new Error("Not implemented");
  }

  winner(): string | null {
    throw new Error("Not implemented");
  }
}

Public test cases

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

Players take turns (core)

var g = new SnakeAndLadder(20, {}, {}, ["ann", "bob"]);
assertEqual(g.move(3), { player: "ann", from: 0, to: 3, won: false });
assertEqual(g.currentPlayer(), "bob");
g.move(2);
assertEqual(g.position("bob"), 2);

Snakes and ladders move you (core)

var g = new SnakeAndLadder(20, { 7: 2 }, { 4: 15 }, ["ann", "bob"]);
assertEqual(g.move(4).to, 15);
assertEqual(g.move(5).to, 5);

Rolls must be 1 to 6 (edge)

var g = new SnakeAndLadder(20, {}, {}, ["ann"]);
assertThrows(function () { g.move(7); });
assertThrows(function () { g.move(0); });

Design & structure checks

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

  • The board is its own class and knows nothing about players or turns: Squares, snakes and ladders are the same whoever plays. A separate board can be tested alone and reused for other rule sets.

Phase 2: Change request

In real interviews, the follow-up tests whether your design is extensible. After your first version passes all 12 tests, you unlock the change request: Sixes.

Relevant low-level design lessons

More low-level design problems