System design · must-tier · asked at Amazon, Apple, Google, Meta, Microsoft, Netflix

Parking Lot

mediumlldoodstate

Prompt

"Design the classes for a parking lot. It has several floors, spots of different sizes, and cars come in and out through a few gates. I want to see the objects, how a vehicle gets a spot, and how the driver pays on the way out."

Clarifying questions

  • What vehicle types and spot sizes exist? Three of each: motorcycle, car, bus, mapped to small, medium, large spots. A vehicle may use a spot of its own size or larger. A bus needs exactly one large spot (no multi-spot vehicles).
  • How many gates, and can they operate at the same time? Two or three entry gates and one or two exit gates, all active concurrently. So park calls can race.
  • How is the spot chosen? Any free spot of a compatible size is acceptable for the first version. Preferring the lowest floor or the spot nearest the gate is a follow-up.
  • How is pricing computed? Hourly, rounded up, with a per-size rate. Keep it pluggable; the interviewer will change the rule later.
  • Does anything need to survive a process restart? No. In-memory is fine; note where persistence would attach.
  • Do we need a display of free spots per floor? Nice to have. It falls out naturally if the lot keeps counters, so plan for it.

Requirements

Functional

  • Park a vehicle: find a compatible free spot, mark it occupied, issue a ticket.
  • Unpark by ticket: compute the fee, free the spot, produce a receipt.
  • Reject a vehicle when no compatible spot exists.
  • Report free-spot counts per floor and size.

Non-functional

  • Correctness under concurrent gates: two vehicles must never be assigned the same spot.
  • park and unpark should be roughly O(1) per call; a lot with a few thousand spots should not scan every spot on each arrival.
  • Pricing and allocation rules are the parts most likely to change, so they must be swappable without touching the core.

Numbers

  • A large garage: 5 floors x 400 spots = 2,000 spots. Peak arrivals of maybe 10 per minute across all gates. This is tiny; the exercise is about structure, not throughput, and stating that early signals you are not over-engineering.

Last reviewed 8 September 2026