Design a Vending Machine
Design a Vending Machine
MediumLLD0% accepted
Design a vending machine that dispenses items, handles payment (coins/notes), gives change, handles out-of-stock, and refunds money. Use State design pattern to manage machine states.
Approach
Design vending machine with state pattern for idle, has-money, dispensing states.
Input
Machine idle; user inserts Rs 10; selects item worth Rs 8
Output
IDLE + money -> HAS_MONEY; select item with enough balance -> DISPENSING; dispense item, return Rs 2 change -> IDLE
More LLD problems
Browse all coding problems →Scenarios & Expected Answers
Sign in to continue
Create a free account to view answers and mark progress.
- Free forever — no credit card
- Theory Q&A with detailed answers
- Points, streaks & leaderboards