Black Friday: 30% off every plan through November 30. See the prices
SysDesignPrep.com
Study guide

Updated 22 November 2026

Parking lot low-level design (LLD): classes, code and follow-ups

The classic LLD question worked end to end. What to ask, the classes and how they relate, the key methods, the follow-ups and the mistakes to avoid.

Reading is half of it. Now try it in an interview.An AI interviewer asks you to design Ticketmaster, out loud or typed, and scores the answer for your level. Or watch a sample interview first, free with no sign-up to start.
Start an AI mock

To design a parking lot in a low-level design interview, agree the scope first: one lot with several levels, spots in three sizes, vehicles that fit a spot of their own size or larger, entrances and exits working at the same time, and a fee by the hour. Then model it with a ParkingLot that owns the levels, a Level that owns its spots, a ParkingSpot that holds at most one vehicle, a Ticket for each stay, and two interfaces for the rules most likely to change: a SpotAssignmentStrategy that picks the spot and a PricingStrategy that computes the fee. Two methods carry the design, park(vehicle) and leave(ticket_id), and the follow-ups test whether it bends without breaking: two cars claiming the last spot at once, a new kind of vehicle, a new pricing rule.

The question is old and still asked: a parking lot is among the low-level design examples in Prepfully's Microsoft interview guide (updated August 2026). This guide works the whiteboard version, which is a 45 to 60 minute conversation, and notes what changes in a machine coding round. For the round itself and the other classic problems, start with the LLD interview guide.

The requirements to clarify

Spend the first five minutes here. Each question below changes a class or a method, which is why it is worth asking. Say the default you would assume, so the interviewer can simply agree or correct you.

  • One lot or many? Assume one lot with several levels. A chain of lots is a follow-up.
  • Which vehicles, and which spots can each use? Assume motorcycles, cars and vans, and small, medium and large spots, where a vehicle fits a free spot of its own size or larger.
  • How many entrances and exits? Assume several, working at the same time. This is where the concurrency question comes from.
  • How is the fee computed? Assume a rate per started hour by spot size, and ask whether there is a daily maximum or a different first hour. The answer lives in one class, so it is cheap to change.
  • Is payment in scope? Usually only as far as "the exit asks for the fee". Leave room for a payment interface and do not design card handling.
  • Which spot does a vehicle get? Assume the lowest level first, then the smallest spot that fits, so large spots stay free for vans. Ask, because nearest to the entrance or nearest to the lift are just as valid, and the interviewer may have one in mind.
  • What does the entrance show? Assume a count of free spots per level and size.
  • What is out of scope for now? Reservations, electric charging, accessible spots, lost tickets. Name them, because most come back as follow-ups.

And the non-functional ones, said in a sentence: one process with its data in memory, no spot ever given to two vehicles, and the same fee every time for the same stay.

The classes and how they relate

  • ParkingLot is what the gates call. It owns the levels, the open tickets and the two strategies, and exposes park(vehicle) and leave(ticket_id).
  • Level has a number and its spots, and can count the free spots of each size for the display.
  • ParkingSpot has an id, a size and the vehicle in it, if any. It decides whether a vehicle fits.
  • Vehicle has a plate and a type, and the type maps to the spot size it needs.
  • Ticket is one stay: the vehicle, the spot and the time it came in.
  • SpotAssignmentStrategy is an interface that picks a spot for a vehicle. LowestLevelFirst is today's rule.
  • PricingStrategy is an interface that computes the fee for a ticket at exit. HourlyBySize is today's rule.
  • A clock is passed in rather than read from the system, so a test can move time forward.

The lot owns its levels and each level owns its spots: they are created together and never shared (composition). A spot refers to the vehicle in it, and a ticket refers to a vehicle and a spot, but none of them owns the others (association). The lot depends on the two strategy interfaces, never on a particular rule, and is given them when it is built. That last choice is what lets a new rule arrive as a new class.

The class design of a parking lot. ParkingLot, with the methods park and leave, sits in the middle. It uses two interfaces, SpotAssignmentStrategy to pick a spot and PricingStrategy to compute the fee, implemented today by LowestLevelFirst and HourlyBySize. ParkingLot has levels, each Level has parking spots, and a ParkingSpot holds zero or one Vehicle. ParkingLot issues a Ticket for each stay, and the ticket refers to the spot.
What varies sits behind the two interfaces on the top row; the lot, its levels and its spots stay the same when a rule changes.

Two modelling choices are worth saying out loud, because interviewers ask about both.

Vehicle types as data, not subclasses. A Car class and a Motorcycle class that extend Vehicle add no behaviour of their own; they only differ in the size they need. A type with a table from type to size says the same thing in one place, and a new type is one more entry. Keep subclasses for when a type really behaves differently.

Vehicle types: subclasses or data

A subclass per type

  • Car, Motorcycle and Van extend Vehicle
  • Each class adds no behaviour, only a size
  • A new type is a new class, and every check on the type needs another branch

One Vehicle with a type

  • The type maps to the spot size it needs
  • The spot's fits() compares sizes, whatever the type
  • A new type is one more entry in the table

Data, until a type has behaviour of its own. Say why when you choose it.

A spot's state. For the core, a spot is free or holds one vehicle, and that is all ParkingSpot stores. When the follow-ups add reservations or maintenance, it becomes an explicit state (free, held, occupied, out of service), and every change goes through the spot so the rules about which change is allowed live in one place.

The key methods

Write the core first: park and leave are where every decision meets. The sketch is Python, but the shape is the same in Java or C++: the interfaces become interfaces or abstract classes, and the lock becomes synchronized or a mutex. In a whiteboard round, the model and these two methods are usually enough code; in machine coding you would add a small driver and tests.

import math, threading, uuid
from abc import ABC, abstractmethod
from dataclasses import dataclass
from datetime import datetime
from enum import Enum, IntEnum

class LotFull(Exception):
    pass

class SpotSize(IntEnum):
    SMALL = 1
    MEDIUM = 2
    LARGE = 3

class VehicleType(Enum):
    MOTORCYCLE = "motorcycle"
    CAR = "car"
    VAN = "van"

NEEDS = {VehicleType.MOTORCYCLE: SpotSize.SMALL,
         VehicleType.CAR: SpotSize.MEDIUM,
         VehicleType.VAN: SpotSize.LARGE}

@dataclass(frozen=True)
class Vehicle:
    plate: str
    type: VehicleType

class ParkingSpot:
    def __init__(self, spot_id: str, size: SpotSize):
        self.id, self.size = spot_id, size
        self.vehicle: Vehicle | None = None   # None: free

    def fits(self, v: Vehicle) -> bool:
        return self.vehicle is None and self.size >= NEEDS[v.type]

@dataclass
class Level:
    number: int
    spots: list[ParkingSpot]

@dataclass
class Ticket:
    id: str
    vehicle: Vehicle
    spot: ParkingSpot
    entered_at: datetime

class SpotAssignmentStrategy(ABC):
    @abstractmethod
    def find_spot(self, levels: list[Level],
                  v: Vehicle) -> ParkingSpot | None: ...

class PricingStrategy(ABC):
    @abstractmethod
    def fee_cents(self, t: Ticket, exited_at: datetime) -> int: ...
class ParkingLot:
    def __init__(self, levels, assign, pricing, clock):
        self.levels, self.assign = levels, assign
        self.pricing, self.clock = pricing, clock
        self.active: dict[str, Ticket] = {}   # open tickets
        self.inside: set[str] = set()         # plates parked
        self.lock = threading.Lock()          # gates share it

    def park(self, v: Vehicle) -> Ticket:
        with self.lock:
            if v.plate in self.inside:
                raise ValueError(f"{v.plate} is already inside")
            spot = self.assign.find_spot(self.levels, v)
            if spot is None:
                raise LotFull()
            spot.vehicle = v
            t = Ticket(uuid.uuid4().hex, v, spot, self.clock())
            self.active[t.id] = t
            self.inside.add(v.plate)
            return t

    def leave(self, ticket_id: str) -> int:
        with self.lock:
            t = self.active.pop(ticket_id)  # KeyError: unknown
            fee = self.pricing.fee_cents(t, self.clock())
            t.spot.vehicle = None
            self.inside.discard(t.vehicle.plate)
            return fee

class LowestLevelFirst(SpotAssignmentStrategy):
    def find_spot(self, levels, v):
        for level in levels:              # lowest level first
            fits = [s for s in level.spots if s.fits(v)]
            if fits:                      # then smallest size
                return min(fits, key=lambda s: s.size)
        return None

class HourlyBySize(PricingStrategy):
    def __init__(self, cents_per_hour: dict[SpotSize, int]):
        self.rates = cents_per_hour

    def fee_cents(self, t, exited_at):
        secs = (exited_at - t.entered_at).total_seconds()
        hours = max(1, math.ceil(secs / 3600))  # started hours
        return hours * self.rates[t.spot.size]

park checks the vehicle is not already inside, asks the strategy for a spot, claims it and issues a ticket, all under one lock. leave closes the ticket, prices it at the clock's current time and frees the spot. The failures are explicit: a full lot, a plate that is already inside, a ticket that is unknown or already used.

Three details interviewers notice. The fee is whole cents, never a floating-point number. The rounding is a stated rule rather than an accident: a stay of a few minutes pays the first hour, and 61 minutes pays two. And the clock is passed in, so a test of a three-hour stay does not wait three hours.

The follow-ups interviewers push

Two cars, one free spot

Gates A and B call park at the same moment. Without the lock, both ask the strategy, both are told spot 2-M4 is free, and both write their car into it: two tickets for one spot, and the second driver finds the first car parked there. Name the race before you fix it.

There are three ways to fix it, and the first one is the answer to give first:

  1. One lock around park and leave, as in the sketch. It is correct by construction, and the work inside it takes microseconds while even a busy entrance lets a car in every few seconds, so no gate waits in practice. Saying why it is enough is the practical answer interviewers look for.
  2. Claim the spot, not the lot. The strategy returns spots in order of preference, and each spot has its own atomic claim: compareAndSet(null, vehicle) on an AtomicReference in Java, a small lock per spot in Python. A gate that loses the claim moves on to the next spot. There is no global lock, but the open tickets and the free counts then need thread-safe structures of their own.
  3. A free list per size. Keep a thread-safe queue of free spots for each size: park takes one off (a single atomic step, so each spot is handed out once) and leave puts it back. Fast and simple, though "nearest first" then needs a priority queue, and "smallest that fits" means trying the queues in order.
class ParkingSpot:
    # ... as before, plus self._claim = threading.Lock()
    def try_claim(self, v: Vehicle) -> bool:
        with self._claim:          # Java: compareAndSet(null, v)
            if not self.fits(v):
                return False
            self.vehicle = v
            return True

# in ParkingLot.park, with no lot-wide lock around the search:
for spot in self.assign.candidates(self.levels, v):
    if spot.try_claim(v):          # lost the race? try the next
        break
else:
    raise LotFull()

Keeping two gates from taking one spot

One lock for the lot

  • park and leave run one at a time
  • Correct by construction, and the code stays short
  • Gates wait microseconds for each other, which nobody notices

A claim per spot

  • Each spot is claimed atomically; the loser tries the next spot
  • No lot-wide lock, so gates never wait on each other
  • The ticket map and free counts need thread-safe structures too

One lock in the interview, with the reason. A claim per spot when the interviewer asks what you would do if one lock were not enough.

If you lock per level instead, never hold two level locks at once, or always take them in the same order, or two gates can each hold one and wait for the other forever. The deadlocks playground shows how that happens.

If the interviewer pushes further, to many lots and a phone app, it stops being one process, and the claim becomes a conditional write in the database: set the spot's vehicle only where it is still empty, and check that one row changed. That is optimistic locking, the same idea as the seat holds in Design Ticketmaster.

A new kind of vehicle

The usual ones are an electric car that needs a charging spot, a bus that needs several large spots in a row, and a driver with an accessible-parking permit.

  • A type that only needs a size is one more entry in the table. Nothing else changes, which is the payoff of modelling types as data.
  • A type that needs a feature: give each spot a set of features (charger, accessible, covered) and each vehicle a set of needs, and let fits check both size and features. The lot and the strategies do not change.
  • A type that needs several spots, like the bus, changes a relationship: a ticket now holds a list of spots, the strategy has to find a run of adjacent free spots on one level, and claiming has to be all or nothing, so the bus gets all five spots or none. Say that it changes the model, and change it; pretending it fits unchanged is worse.

Each of these also raises a policy question for the interviewer, such as whether an electric car may take an ordinary spot when the chargers are full. Ask it, then put the answer in the assignment strategy, not in the lot.

Pricing strategies

The rules that come up are a different first hour, a daily maximum, a night or weekend rate, a flat fee during an event, a charge for a lost ticket, and monthly passes that pay nothing at the exit.

  • Each rule is a pricing strategy, and rules combine rather than multiply. A daily maximum is a strategy that wraps another one and caps its result (the decorator pattern), so you never write a class for every combination.
  • Fix the rule at entry. Store the pricing strategy, or its version, on the ticket when the car comes in, so a price change at noon does not reprice a car that arrived at nine.
  • Split stays that cross a boundary. A stay from 5:30 pm to 8:30 pm with a night rate from 6 pm is two intervals priced separately. Test the boundary minutes.
  • Paying and leaving are two steps in most real lots: a quote at the pay station, then the barrier, with a few minutes' grace in between. If the interviewer cares, leave becomes quote(ticket_id) and exit(ticket_id).

Extensions the interviewer may test

  • More than one lot. One ParkingLot object per site, found by site id. A singleton lot would block this, and would make every test share one lot.
  • Display boards. The observer pattern: the lot publishes "spot taken" and "spot freed" events, and each board keeps its own counts. The lot does not know how many boards there are.
  • Reservations. A held state with an expiry: a reserved car's arrival turns held into occupied, and an expired hold goes back to free. The reservation holds playground shows the expiry at work.
  • Payment methods. A PaymentMethod interface behind the exit (card, cash, app); the lot learns only whether the fee was paid.
  • Restarting without losing tickets. A repository interface for tickets and spots, kept in memory in the interview and backed by a database in production.

Common mistakes

  • Classes before requirements. Drawing ParkingLot, Floor and Spot before asking about sizes, gates or pricing, then redrawing when the answers arrive.
  • A subclass for every vehicle and every spot, each adding nothing but a size.
  • One class that does everything: ParkingLot.park with the pricing branches, the spot search and the payment all inline.
  • Money as a floating-point number, and no stated rule for part of an hour.
  • Reading the system clock inside the pricing code, which makes every time-based case untestable.
  • Ignoring the second gate, or the opposite: a distributed lock service for a single process.
  • Making the lot a singleton because there is only one lot today.
  • A diagram and no code when the round expects code. Write park and leave.
  • Answering with load balancers and databases. That is the high-level design round; if you are not sure which one you are in, ask.

A sample of the dialogue

How the first minutes and two of the follow-ups can sound. The questions come first, and every choice comes with its reason.

Interviewer: Design a parking lot.

Candidate: Before the classes, a few questions. One lot or a chain of them? How many levels, and which vehicles? Can a motorcycle use a car spot?

Interviewer: One lot, three levels. Motorcycles, cars and vans, and a smaller vehicle can use a bigger spot.

Candidate: Then each spot gets a size, small, medium or large, and a vehicle fits a free spot of its size or bigger. How is the fee worked out?

Interviewer: Hourly, and it depends on the spot.

Candidate: I will charge per started hour by the spot's size, and put pricing behind an interface, since it is the rule most likely to change. Is there more than one entrance?

Interviewer: Two entrances, two exits.

Candidate: Then park can run twice at the same moment, so claiming a spot has to be safe. I will start with one lock around park and leave: the work inside takes microseconds, so the gates will not notice it. If you want more throughput, I would move to an atomic claim per spot.

Interviewer: We are adding charging spots for electric cars.

Candidate: A charging spot is still a spot, with a feature. I would give spots a set of features and vehicles a set of needs, and fits checks both. The lot does not change. Should an electric car take an ordinary spot when the chargers are full?

Interviewer: Yes. Why not a ChargingSpot subclass?

Candidate: It would add a flag and no behaviour. If charging later needs a meter and a session, that is a charging session attached to the ticket, not a different kind of spot. And the fallback you just described goes into the assignment strategy, as its rule.

The same prompt at the high level

Asked in a system design round, "design a parking lot" usually means many lots and an app: drivers search for space near a place and time, reserve, pay, and the gate recognises the plate. The hard parts are search, holds that expire, never selling one spot twice across many servers, and payments. Bookings and reservations covers holds and double booking, and the Ticketmaster walkthrough works the same claim problem under a flash crowd.

If your loop has that round too, make a study plan for it in the planner and sit a system design mock interview when you are ready. SysDesignPrep.com's mock interviews are high-level design rounds, not LLD. For the LLD round itself, the LLD interview guide has the method, how to prepare and the other classic problems.

Questions people ask

How do you design a parking lot in a low-level design interview?

Agree the scope first: one lot with levels, spots in three sizes, vehicles that fit their own size or larger, several gates at once, and an hourly fee. Then model a ParkingLot that owns Levels and ParkingSpots, a Ticket per stay, and two interfaces for the rules that change, a SpotAssignmentStrategy and a PricingStrategy. Write park and leave, then handle the follow-ups: two cars racing for the last spot, new vehicle types and new pricing rules.

What classes are in a parking lot design?

ParkingLot (what the gates call, with park and leave), Level, ParkingSpot (size and the vehicle in it), Vehicle (plate and type), Ticket (vehicle, spot and time in), and two interfaces: SpotAssignmentStrategy to choose a spot and PricingStrategy to compute the fee. A clock passed into the lot makes time-based behaviour testable. The lot owns its levels and each level owns its spots.

Which design patterns does a parking lot LLD use?

Strategy, for how a spot is chosen and how a fee is computed, so a new rule is a new class. Observer, if display boards must track free spots. Decorator, to add a daily maximum on top of an hourly rate without a class for every combination. Name a pattern only together with the problem it solves.

How do you stop two cars from getting the same parking spot?

The simplest correct answer is one lock around park and leave, which costs microseconds per car. Without a lot-wide lock, give each spot an atomic claim, such as compareAndSet on an AtomicReference in Java, and let a gate that loses the claim try the next spot. Across many servers, the claim becomes a conditional database write that only succeeds while the spot is still empty.

How do you add a new vehicle type to a parking lot design?

If vehicle types are data, a type that only needs a size is one more entry in the table from type to spot size. A type that needs a feature, such as an electric car that needs a charger, is handled by giving spots features and vehicles needs and checking both in fits. A vehicle that needs several spots, such as a bus, changes the model: a ticket holds several spots, and claiming them is all or nothing.

Do I need to write code for the parking lot question?

Usually yes, at least the core. In a 45 to 60 minute low-level design round, write the class signatures and the park and leave methods in real code. In a machine coding round of about 90 minutes, write a program that runs, with the data in memory and a small driver or tests. Ask at the start how much code the interviewer wants to see.