Before you start
Welcome to LLD problems. You've done 25 lessons of foundation work. Now you use them.
Every lesson in this module has ONE shape:
- Read the requirements.
- Ask the questions a strong interviewer would want to hear.
- Decide on entities, patterns, and trade-offs.
- WRITE THAT DOWN in
design.md. - Implement in
main.py.
The tests grade BOTH. Design without implementation fails. Implementation without design also fails.
Why we grade design.md too
Every design interview asks two things:
- Can you build it? (implementation)
- Can you defend it? (justification)
Half of candidates fail on #2 — they built something that works but can't explain why they made the choices they made. "I used Factory because... um... it seemed right?" is a common interview failure.
The design.md forces you to say the reasoning out loud BEFORE the interviewer asks. That's not busy-work; that's the interview rehearsal.
The interview flow this simulates
In a real 45-minute design interview:
- Minutes 0-5 — read the problem, ask clarifying questions
- Minutes 5-15 — find the classes, sketch them, name the patterns you plan to use
- Minutes 15-40 — implement
- Minutes 40-45 — walk the interviewer through your design and defend the choices
Modules 1-3 taught the ingredients. Module 4 teaches the flow.
Reading the requirements
Read them TWICE. First pass: understand what the machine does. Second pass: mark things up. Look for:
- State transitions. "In idle, it accepts coins. When dispensing, all actions return 'busy'." → State pattern signal.
- Swappable behavior. "New denominations are added over time." → Registry / dispatch signal.
- Cross-cutting rules. "Every successful dispense must decrement stock." → An invariant to enforce in ONE place.
- Growth axes. "Later we'll add UPI payments." → Design for extension NOW, not later.
Write those observations down BEFORE picking patterns. The patterns fall out of the observations.
How to write a good design.md
Don't try to write it top-to-bottom in one pass. Iterate:
- First pass, 3 minutes. Skeleton — one line per section with your gut answer.
- Second pass, 5 minutes. Fill in why. For patterns, ask yourself the module-3 questions ("is this the family rule?" for Abstract Factory, "does state transition?" for State, etc.).
- Third pass, after implementing. Add anything you learned while coding. Your first-pass choices may have shifted.
The tests check:
- Every section has real content (60+ chars beyond the stub).
- No placeholder strings (
TODO,YOUR ANSWER HERE, etc.) survive. - The Patterns section mentions at least one module-1-3 pattern OR explicitly justifies plain classes.
Meeting all three is a low bar for interview-quality design justification.
For this specific problem — hints without spoiling
The vending machine has signals for at least ONE behavioral pattern (think: what changes over time?) and one structural or creational pattern (think: what do you build based on data?).
Don't reach for patterns you don't need. If a plain class does the job — say so and defend that. Over-engineering is also a design failure.
What the AI Code Review adds
The grader checks structure. It can't tell whether your Patterns section's REASONING is good — only that reasoning exists. That's what the "Ask Claude for a code review" button after grading is for. Claude reads your design.md AND main.py and comments on the actual quality of your choices.
Use it. That feedback loop is worth more than three more lessons of drill.
Structure of the whole module
12 problems, ordered roughly by difficulty:
- Vending Machine (this lesson)
- Parking Lot
- Tic-Tac-Toe
- Snake and Ladder
- Elevator
- Splitwise
- Movie Booking
- LRU Cache
- Rate Limiter
- File System
- Chess
- Ride Matching
Same template throughout: design.md + main.py, both graded.