Design a parking lot system
MediumConceptClassic LLD Problems
Answer
Model a multi-floor lot that issues a ticket on entry, assigns a suitable spot, and charges on exit. Key requirements are several vehicle and spot sizes, multiple entry and exit gates, and a configurable fee model.
- Core classes:
ParkingLot,Floor,ParkingSpotwith aSpotTypeenum,Vehiclewith aVehicleTypeenum,Ticket,EntryGate,ExitGateandPayment. - Patterns: a
SpotAllocationStrategy(nearest first, or fill by floor) and aFeeStrategy(hourly or flat) keep policies replaceable; a factory can create vehicles. - Concurrency: two gates may try to claim the same spot, so assignment must be atomic, for example by locking per floor or using compare-and-set on the spot.
- Keep free spots of each type in a set or queue for
O(1)allocation.
More in Classic LLD Problems
| # | Problem | Platform | Difficulty | Open | 1st1st Visit | 2nd2nd Visit | RevRevise |
|---|---|---|---|---|---|---|---|
| 1 | Design a parking lot system | Concept | Medium | Read the answer to Design a parking lot system | |||
| 2 | Design a vending machine | Concept | Medium | Read the answer to Design a vending machine | |||
| 3 | Design an elevator system | Concept | Hard | Read the answer to Design an elevator system | |||
| 4 | Design a movie ticket booking system | Concept | Hard | Read the answer to Design a movie ticket booking system |