Skip to main content
Intermediatesystem design

Design a vending machine: the user selects a product, inserts cash, and receives the product and the correct change.

ReportedSource: GeeksforGeeks interview experience: Airbnb on-campus

Quick answerFree

State pattern (Idle, Selected, Collecting, Dispensing), inventory and cash box with denomination counts, change via greedy or bounded DP over available coins, refuse/refund when exact change is impossible, atomic dispense + change.

Detailed answer· ~150 words

Interview Prep

Unlock the full answer with Interview Prep

Get a ~150-word model answer, plus 91 more System Design questions.

Also in Pro (₹499 / 90 days).

+ 91 more System Design questions in Interview Prep, each with the full answer.

Discussion