Parking Lot System – Low Level Design Interview Practice
Practise the Parking Lot System low level design problem the way an LLD round actually runs. You are asked for requirements first, then a class model, and then to extend the design when a new requirement lands part way through – the follow-up that separates a design that was memorised from one that was understood.
The round checks the things interviewers grade: whether your classes carry single responsibilities, whether you reached for a design pattern or reinvented one, whether the design absorbs a new requirement without rewriting what exists, and whether you can explain a trade-off out loud. Feedback covers class modelling, SOLID principles, use of patterns, extensibility and communication.
What this question is really testing
Pricing and allocation as separate concerns. The class model is straightforward; the marks are in keeping fee calculation out of the ticket and spot selection out of the floor.
Requirements to establish first
- Support several vehicle sizes against several spot sizes, where a bike may take a car spot but not the reverse.
- Issue a ticket on entry and settle it on exit.
- Charge by duration, with rates that differ by vehicle type and may differ by hour or day.
- Report free spots per floor so entry gates can turn vehicles away.
- Handle several gates admitting vehicles at the same moment without double-allocating a spot.
Core classes
- ParkingSpot – One physical space, its size, and whether it is occupied.
- ParkingFloor – Owns its spots and answers "do you have room for this vehicle?".
- SpotAllocationStrategy – Chooses which free spot to hand out - nearest to the lift, first fit, or by size.
- Ticket – Vehicle, spot, entry time. It records; it does not price.
- PricingStrategy – Turns a ticket and an exit time into an amount.
- ParkingLot – The facade the gates talk to. Often a singleton, and the one place that is defensible.
Design patterns that apply
- Strategy – Twice over, and they are independent: how a spot is chosen, and how time is priced. Interviewers look for both, and for the fact that they do not know about each other.
- Factory – Vehicle and spot creation from a type code, so adding an EV spot touches one factory rather than every call site.
- Singleton – One lot per process. Say why you want it, and say that it makes testing harder - that trade-off is part of the answer.
Follow-up questions to expect
- Add electric spots with charging. Is that a new size, a new attribute, or a new subtype - and what does each choice cost you later?
- Introduce monthly pass holders who are not charged on exit. Where does that go without an if-statement in the pricing strategy?
- Two entry gates allocate the last free spot at the same instant. Show the lock and say what it guards.
Where candidates lose marks
- Calculating the fee inside Ticket, which fuses a record with a policy.
- An isAvailable boolean on ParkingLot rather than asking the floors, so the counter drifts from reality.
- Assuming one spot type per vehicle type, which collapses the moment a bike is allowed in a car spot.