Design a parking lot system — you have 90 minutes, working code at the end.
In a parking lot machine coding round, scope one deterministic flow of park, unpark and charge, model Vehicle, Slot, Level, Ticket and a ParkingLot facade, then push slot allocation and pricing behind strategy interfaces so review-time variants are configuration rather than surgery.
Answer
Short answer
For a parking lot machine coding round, build one running end-to-end flow before adding features: park a vehicle, allocate a slot, issue a ticket, unpark, and compute the fee. The design should separate slot allocation and pricing behind strategy interfaces so variants such as nearest slot, monthly pass, or slab pricing add classes rather than if chains. Say what is out of scope early so the interviewer can grade working code, not imagined architecture.
Was this answer helpful?
Likely follow-ups
- Two cars request the last available slot at the same instant — where exactly is your lock, and what is its granularity?
- How would you support a monthly pass holder who parks free, without adding an if-branch to the pricing code?
- The lot now spans ten levels and slot lookup is the bottleneck — what data structure replaces your linear scan?
- How would you persist and rebuild lot state after a restart without leaking JPA annotations into your domain model?
Related questions
- You may use an AI coding assistant in the machine-coding round. What do you still write yourself, and what do you ask it for?mediumAlso on machine-coding and object-oriented-design5 min
- Design a food-ordering system: customers place orders with restaurants, and the system assigns a delivery partner. Walk me through the classes.mediumAlso on machine-coding and strategy-pattern5 min
- Design an elevator system for a building with N lifts. When someone presses the call button, which lift answers, and where in your code is that decided?hardAlso on strategy-pattern and machine-coding6 min
- Write a game where two players take turns and either of them can win. What do you model, and where does the win check belong?mediumAlso on machine-coding and object-oriented-design6 min