Machine-Coding Walkthrough: Snake & Ladder
Beginner · 22 min read · Low-Level Design, Case Studies: Core
A minute-by-minute 90-minute round: scoping, design, code by minute 40, tests and extensions.
Snake & Ladder is the classic 90-minute machine-coding round: small enough to finish, open enough to show judgment. This lesson is a minute-by-minute walkthrough of one strong attempt — what to say, what to type, and what to leave out — ending in a complete, tested solution.
Use it as a rehearsal script. The timings matter as much as the code.
What the interviewer expects
Unlike the other case studies, the code in this lesson is interview-sized: it's what one strong candidate typed in 90 minutes. Here is what that time goes on:
The prompt
Minutes 0–10: clarify, then commit
Ask a few questions, state assumptions for the rest, and write them down where the interviewer can see them.
Minutes 10–20: entities and variation points
Nouns from the prompt: board, cell, snake, ladder, player, die, turn, game. Then trim:
Minutes 20–60: code the core, run it early
Write in this order, and run something by minute 40.
Minutes 60–75: tests and edge cases
With scripted dice, every rule becomes a one-line assertion:
Minutes 75–90: extensions the interviewer will ask for
What made this attempt strong
Interview questions
- Why make the dice an interface when there's only one real die?
- How do you detect an invalid board where snakes and ladders form a loop?
- The interviewer adds: rolling a six gives another turn, but three sixes in a row sends you back to start. Where does that go?
Further reading
Key takeaways
- In a machine-coding round, scope in 10 minutes, design in 10, and have code running by minute 40.
- Model only what varies or carries rules: jumps as a map, dice and move rules as interfaces.
- A deque makes turn order and dropping finished players trivial.
- Inject randomness so every rule is testable; add a randomised robustness test if time allows.
- Validate inputs (loops, out-of-range jumps) in constructors.
Previous: Schema Design for LLD · Next: Design a Parking Lot