Skip to main content
System DesignDSA & Coding

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.

InterviewPilot TeamNovember 11, 20265 min read

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:

  1. How many floors? Multiple, each with many spots.
  2. Vehicle types? Bike, car, truck (or small, medium, large).
  3. Can a small vehicle use a bigger spot? Usually yes, when its own size is full.
  4. Pricing? Per hour, possibly different per vehicle size; first hour minimum.
  5. Entry and exit gates? Several, possibly in parallel. This raises concurrency.
  6. Payment? Usually out of scope; return the fee.
  7. Display boards showing free spots per floor? Nice to have.

Entities

ClassResponsibility
SizeSMALL < MEDIUM < LARGE
Vehicleplate, size
Spotid, floor, size, current vehicle
Floorits spots; free counts by size
Ticketid, vehicle, spot, entry time
AllocationStrategypicks a free spot for a vehicle
PricingStrategyfee for a ticket and exit time
ParkingLotpark, 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.

Try it freeHow the AI interview assistant works3 free sessions a day · Windows 10/11 · no card required

Follow-ups interviewers ask

Follow-upHow the design absorbs it
Weekend or night pricingNew PricingStrategy
Nearest spot to the entry gateNew AllocationStrategy taking a gate
EV charging spotsAdd a features set to Spot; filter in allocation
Reserved / VIP spotsFlag on Spot; allocation skips them unless the ticket allows
Display boards per floorObserver: spots publish changes; boards subscribe
Lost ticketLook up by plate; charge a flat maximum
Multiple lots in a cityBecomes an HLD problem: availability service, booking, payments

Mistakes that cost points

  • A ParkingLot class 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.

Frequently asked questions

Almost always LLD or machine coding. In an HLD round it would become a multi-lot booking system with payments and sensors, which is a different problem.

A size enum on one Vehicle class is usually enough. Use subclasses only if types behave differently, for example an EV that needs a charging spot.

A working park/exit flow with pricing and a small demo. Display boards, payments and admin features are usually discussion-only.

Strategy for allocation and pricing, Factory if vehicles or spots get complex, and Singleton is sometimes suggested for the lot, though dependency injection is cleaner.

Was this article useful?

Discussion

No comments yet. Been through an interview like this? Your experience could help the next candidate.

You’re posting anonymously — it appears after a quick review. Sign in to post under your name instantly.
0/2000

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.