Design a Parking Lot: Low-Level Design Interview Walkthrough
The parking lot LLD problem solved end to end: clarifying questions, entities, spot allocation and pricing as Strategies, tickets, multiple floors and gates, runnable Python code, concurrency, and the follow-ups interviewers ask.
The parking lot is the "hello world" of low-level design. Because everyone has seen it, interviewers judge it harder: they expect clean extension points, not just a working loop. Our LLD guide has a 30-line sketch; this is the full interview version.
Clarifying questions
Ask these, then state your assumptions:
- How many floors? Multiple, each with many spots.
- Vehicle types? Bike, car, truck (or small, medium, large).
- Can a small vehicle use a bigger spot? Usually yes, when its own size is full.
- Pricing? Per hour, possibly different per vehicle size; first hour minimum.
- Entry and exit gates? Several, possibly in parallel. This raises concurrency.
- Payment? Usually out of scope; return the fee.
- Display boards showing free spots per floor? Nice to have.
Entities
| Class | Responsibility |
|---|---|
Size | SMALL < MEDIUM < LARGE |
Vehicle | plate, size |
Spot | id, floor, size, current vehicle |
Floor | its spots; free counts by size |
Ticket | id, vehicle, spot, entry time |
AllocationStrategy | picks a free spot for a vehicle |
PricingStrategy | fee for a ticket and exit time |
ParkingLot | park, exit, availability; owns a lock |
Extension points: the allocation rule (nearest to gate, lowest floor, exact-size first) and the pricing rule (hourly, weekend, flat for EVs). Both are Strategies, so a new rule is a new class.
Why sizes beat a type matrix
Instead of if vehicle is Bike and spot is Compact or …, give both a comparable size. A vehicle fits a spot if spot.size >= vehicle.size. Adding a new vehicle type is then just a new size value.
The code
import itertools
import math
import threading
from dataclasses import dataclass, field
from datetime import datetime, timedelta
from enum import IntEnum
class Size(IntEnum):
SMALL = 1 # bike
MEDIUM = 2 # car
LARGE = 3 # truck / bus
@dataclass(frozen=True)
class Vehicle:
plate: str
size: Size
@dataclass
class Spot:
spot_id: str
floor: int
size: Size
vehicle: Vehicle | None = None
def fits(self, v: Vehicle) -> bool:
return self.vehicle is None and self.size >= v.size
@dataclass
class Ticket:
ticket_id: int
vehicle: Vehicle
spot: Spot
entered_at: datetime
class AllocationStrategy:
def choose(self, spots: list[Spot], v: Vehicle) -> Spot | None:
raise NotImplementedError
class SmallestFitFirst(AllocationStrategy):
"""Prefer the tightest spot, then the lowest floor, so big spots stay free."""
def choose(self, spots, v):
free = [s for s in spots if s.fits(v)]
return min(free, key=lambda s: (s.size, s.floor, s.spot_id), default=None)
class PricingStrategy:
def fee(self, ticket: Ticket, exited_at: datetime) -> int:
raise NotImplementedError
class HourlyBySize(PricingStrategy):
RATES = {Size.SMALL: 20, Size.MEDIUM: 50, Size.LARGE: 100} # rupees per hour
def fee(self, ticket, exited_at):
hours = max(1, math.ceil((exited_at - ticket.entered_at).total_seconds() / 3600))
return hours * self.RATES[ticket.vehicle.size]
@dataclass
class ParkingLot:
spots: list[Spot]
allocation: AllocationStrategy
pricing: PricingStrategy
_active: dict[str, Ticket] = field(default_factory=dict)
_ids: itertools.count = field(default_factory=lambda: itertools.count(1))
_lock: threading.Lock = field(default_factory=threading.Lock)
def park(self, v: Vehicle, now: datetime) -> Ticket:
with self._lock: # choosing and claiming a spot must be atomic
if v.plate in self._active:
raise ValueError(f"{v.plate} is already parked")
spot = self.allocation.choose(self.spots, v)
if spot is None:
raise RuntimeError(f"no spot for {v.size.name} vehicle")
spot.vehicle = v
ticket = Ticket(next(self._ids), v, spot, now)
self._active[v.plate] = ticket
return ticket
def exit(self, plate: str, now: datetime) -> int:
with self._lock:
ticket = self._active.pop(plate, None)
if ticket is None:
raise ValueError(f"no active ticket for {plate}")
ticket.spot.vehicle = None
return self.pricing.fee(ticket, now)
def free_count(self) -> dict[str, int]:
counts = {s.name: 0 for s in Size}
for spot in self.spots:
if spot.vehicle is None:
counts[spot.size.name] += 1
return counts
def build_lot(floors: int) -> ParkingLot:
layout = [Size.SMALL] * 2 + [Size.MEDIUM] * 3 + [Size.LARGE]
spots = [Spot(f"F{f}-{i}", f, size) for f in range(floors) for i, size in enumerate(layout)]
return ParkingLot(spots, SmallestFitFirst(), HourlyBySize())
if __name__ == "__main__":
lot = build_lot(floors=2)
t0 = datetime(2026, 11, 11, 9, 0)
car = lot.park(Vehicle("KA01AB1234", Size.MEDIUM), t0)
bike = lot.park(Vehicle("KA02CD5678", Size.SMALL), t0)
print(car.spot.spot_id, bike.spot.spot_id) # F0-2 F0-0
print(lot.exit("KA01AB1234", t0 + timedelta(hours=2, minutes=10))) # 150
print(lot.free_count())Walk the interviewer through the demo: the car took the first medium spot, the bike the first small spot, and a 2h10m stay is billed as 3 hours.
Edge cases to handle aloud
- The same plate parking twice.
- Exiting with no ticket (or a duplicate exit).
- Lot full for that size but a larger spot free: handled by
size >= vehicle.size. - Lot completely full: a clear error.
- Clock problems: exit time before entry time should be rejected in a real system.
Concurrency
With several gates, two threads can pick the same free spot. Here, one lock around choose-and-claim makes it atomic. Mention the trade-offs:
- One global lock: simple, but every gate waits on it. Fine for one lot.
- Per-floor locks: more parallelism; gates try floors in order.
- Optimistic claim: compare-and-set on the spot; retry another spot on conflict.
LLD round tomorrow?
InterviewPilot's machine-coding round focus answers in requirements → entities → extension points → code, and keeps that format for the whole session. The overlay stays out of Zoom, Meet and Teams screen shares.
Follow-ups interviewers ask
| Follow-up | How the design absorbs it |
|---|---|
| Weekend or night pricing | New PricingStrategy |
| Nearest spot to the entry gate | New AllocationStrategy taking a gate |
| EV charging spots | Add a features set to Spot; filter in allocation |
| Reserved / VIP spots | Flag on Spot; allocation skips them unless the ticket allows |
| Display boards per floor | Observer: spots publish changes; boards subscribe |
| Lost ticket | Look up by plate; charge a flat maximum |
| Multiple lots in a city | Becomes an HLD problem: availability service, booking, payments |
Mistakes that cost points
- A
ParkingLotclass with every rule hard-coded inside it. - A matrix of vehicle-type × spot-type conditionals.
- Using floats for money.
- No answer to "what if two cars arrive at once?"
- Spending 30 minutes on display boards before parking works.
Related
- Design Splitwise
- Design an elevator system
- Low-level design and machine coding guide
- The coding interview guide for India
Frequently asked questions
Was this article useful?
Bring backup into your next round.
Install InterviewPilot, upload your resume, and walk in with structured answers a keystroke away — visible to you and nobody else.
More from the blog
Design BookMyShow: Machine Coding Round Walkthrough
The movie ticket booking machine coding problem solved end to end: requirements, entities, seat holds with expiry, concurrency-safe booking, pricing by seat type, runnable Python code, and the follow-ups interviewers push on.
Design Splitwise: Machine Coding Round Walkthrough
A complete walkthrough of the Splitwise / expense-sharing machine coding problem: requirements, entities, a Strategy-based split design, balance tracking, debt simplification, runnable Java code, and the follow-up questions interviewers ask.
Low-Level Design and Machine Coding Round: A Practical Guide
How to approach a machine coding or low-level design interview: a time-boxed workflow, the object-oriented principles interviewers check, a worked parking-lot example, common problems, and mistakes that lose points.
Discussion
No comments yet. Been through an interview like this? Your experience could help the next candidate.