intro practice · system design prompt

Design a vending machine

Draw the state machine for a vending machine: Idle → Coin → Selecting → Dispense → Idle, plus refund / out-of-stock branches. List every transition trigger.

The mechanism

A state machine is a fixed set of states plus the rules for moving between them. The win is that illegal transitions become impossible by design — if you find yourself writing many "if status == X and Y" checks, you are simulating a state machine the hard way.

Study State Machines

Expected evidence

A state diagram with 5-7 states, transitions labeled by input event.

Try this drill in the practice workspace →

Hints when you need them
  • What does pressing a button do in each state?
  • Where does coin-return live?

Check the sources

Browse all practice briefs