solidcodersolidcoder
Explore Courses
solidcodersolidcoder

Practical courses for software engineering interviews — no gatekeeping, no fluff.

Company-wise Questions

  • Flipkart Machine Coding Questions
  • Swiggy Machine Coding Questions
  • Meesho Machine Coding Questions

Machine Coding Tutorial

  • Machine Coding Tutorial

Explore

  • Courses
  • About
  • Privacy Policy
  • Terms

© 2026 solidcoder · Practical courses for software engineering interviews.

Built for the AI era — learn by doing.

Home/Machine Coding/Swiggy Machine Coding Questions/Design a Parking Lot System
Chapters — Swiggy Machine Coding Questions▾

Design a Parking Lot System

Machine Coding·SDE-2+·5 min read·Sep 11, 2026

Build an in-memory parking lot management system that assigns vehicles to appropriate slots, generates parking tickets, handles vehicle exit, and provides real-time parking availability.

Asked inSwiggyGo-JekUdaanWayfair

Design and implement a parking lot management system that can manage multiple floors and parking slots while efficiently assigning available parking spaces to incoming vehicles.

The system should support different types of vehicles and ensure that a vehicle is parked only in a compatible slot.

For example, consider a parking lot with 2 floors, where every floor contains 6 slots. Each floor follows this layout:

Slot 1 → Truck
Slot 2 → Bike
Slot 3 → Bike
Slot 4 → Car
Slot 5 → Car
Slot 6 → Car

When a car arrives, the system should find the first available car slot by checking floors from the lowest floor to the highest floor. If Floor 1 has an available slot 4, the car should be parked there instead of using a slot on Floor 2. Once the vehicle is parked, the system should generate a ticket identifying its exact location.

What the round tests

This one tests whether you can model floor and slot allocation cleanly — type-compatible slot search with floor-then-slot priority, ticket generation, and real-time availability queries — while keeping the design open to dynamic layouts, multiple lots, and pricing.

Objective

The primary objective is to design and implement an in-memory parking lot system that supports configurable floors and slots per floor, type-compatible parking with first-available strategy, ticket-based unparking, and real-time display of free and occupied slots.

Functional Requirements

Three tiers of scope

Requirements are split into three tiers so you know what to prioritize under time pressure: build first, build if time allows, and handle edge cases correctly.

Part 1 — Basic Requirements

Core functionality you must build and get working first.

1. Parking Lot

Parking lot creation
Field
Detail
Parking lot ID
Unique identifier (e.g., PR1234).
Number of floors
Configurable — e.g., 2 floors.
Slots per floor
Configurable — e.g., 6 slots on every floor.
Scope
Assume only one parking lot for this problem.

Example:

create_parking_lot PR1234 2 6

Creates:

Floor 1 → 6 slots
Floor 2 → 6 slots

2. Parking Floors

Floor layout (fixed per floor)
Slot
Type / Capacity
Slot 1
Truck — 1 per spot
Slot 2
Bike — up to 4 per spot
Slot 3
Bike — up to 4 per spot
Slot 4 onwards
Car — up to 2 per spot

For example, with 6 slots:

Floor 1

1       2       3       4       5       6
Truck   Bike    Bike    Car     Car     Car
(1)    (4)     (4)     (2)     (2)     (2)  ← capacity per spot

The same layout is repeated for every floor. Slots on each floor are numbered sequentially starting from 1. A single spot is homogeneous — it holds only one category at a time (either 1-4 bikes OR 1-2 cars OR 1 truck); a bike and a car never share the same spot.

3. Vehicles

Supported vehicle types
Type
Detail
CAR
Requires a Car slot.
BIKE
Requires a Bike slot.
TRUCK
Requires a Truck slot.

Every vehicle has:

  • Vehicle type
  • Registration number
  • Color

Example:

Type: CAR
Registration: KA-01-DB-1234
Color: black

4. Parking a Vehicle

Park flow
Step
Action
1. Find
Locate the first suitable free slot.
2. Reserve
Mark the slot as occupied.
3. Park
Associate the vehicle with the slot.
4. Ticket
Generate a ticket ID.
5. Return
Return the ticket ID to the caller.

A slot is suitable only when its configured vehicle type matches the incoming vehicle — a CAR cannot be parked in a BIKE slot. The spot must also have capacity left and remain homogeneous (a bike spot with 2 bikes can take 2 more bikes, but not a car).

5. Finding the Parking Slot

Selection priority
Priority
Rule
1. Lowest floor
Check floors in ascending order (1 → 2 → 3...).
2. Lowest slot
Within a floor, check slots in ascending order (nearest to entry when entries are at corners).
3. Compatible type
Slot type must match vehicle type.
4. Available & homogeneous
Slot must have capacity left (Bike 4, Car 2, Truck 1) and same category as vehicles already there.

For example, suppose:

Floor 1: Slot 4 → Occupied, Slot 5 → Free, Slot 6 → Free
Floor 2: Slot 4 → Free

A new car must be assigned Floor 1, Slot 5 — it should not jump to Floor 2.

6. Parking Ticket

Ticket format
Field
Detail
Format
<parking-lot-id>_<floor-number>_<slot-number>
Example
PR1234_2_5 → Lot PR1234, Floor 2, Slot 5

7. Unparking a Vehicle

Unpark flow
Step
Action
Validate ticket
Check lot ID, floor, slot existence and occupancy.
Locate
Find the corresponding floor and slot.
Retrieve
Get the parked vehicle details.
Free
Mark the slot as available.
Output
Print registration number and color.

Example:

unpark_vehicle PR1234_2_5

If the ticket is invalid or the slot is already empty:

Invalid Ticket

8. Display Parking Information

Display & query commands
Command
What it shows
display free_count <type>
Number of free slots per floor for the vehicle type.
display free_slots <type>
Slot numbers that are currently free per floor.
display occupied_slots <type>
Slot numbers currently occupied per floor.
display registration_numbers_for_cars_with_colour <colour>
Registration numbers of all cars with the colour.
display slot_number_for_registration_number <reg>
Slot number where the car with the reg is parked.
display slot_numbers_for_cars_with_colour <colour>
Slot numbers where cars of the colour are parked.

Examples:

display free_count CAR
→ No. of free slots for CAR on Floor 1: 3
  No. of free slots for CAR on Floor 2: 2

display free_slots BIKE
→ Free slots for BIKE on Floor 1: 2,3
  Free slots for BIKE on Floor 2: 2

display occupied_slots CAR
→ Occupied slots for CAR on Floor 1: 4,5
  Occupied slots for CAR on Floor 2: 6

display registration_numbers_for_cars_with_colour black
→ KA-01-DB-1234, KA-01-DB-1133

display slot_number_for_registration_number KA-01-DB-1234
→ 4

display slot_numbers_for_cars_with_colour black
→ 4,6

Part 2 — Bonus Features

Bonus — score higher if time allows

Extensibility checks — can your design support dynamic layouts, multiple lots, and history/pricing without a rewrite.

Bonus features
Feature
Description
Dynamic Slot Types
Allow different floors to have different slot configurations instead of the same Truck/Bike/Bike/Car layout.
Multi-capacity homogeneous spots
Bike 4, Car 2, Truck/Bus 1 per spot; a spot never mixes categories.
Nearest-entry allocation
Multiple entry points (4 corners); allocate the compatible spot with minimum distance to any entry/lane.
Colour & registration queries
The 3 query commands above — keep them O(1) via reg→slot and colour→regs maps.
Multiple Parking Lots
Support more than one parking lot and allow vehicles to be parked in a selected lot.
Parking History
Maintain the history of vehicles that have entered and exited the parking lot.
Parking Duration
Record entry and exit timestamps and calculate how long a vehicle was parked.
Pricing
Calculate parking charges based on vehicle type and parking duration (e.g., Bike ₹10/hr, Car ₹20/hr, Truck ₹30/hr — assumption stated).

Part 3 — Validations & Edge Cases

1. Slot Compatibility

Compatibility rule
Vehicle
Allowed slot
Truck
Truck slot only
Bike
Bike slot only
Car
Car slot only

A bike cannot occupy a car slot even if the car slot is empty.

2. Slot Numbering

Slots on each floor start from 1 and restart for every floor — Floor 1 → 1,2,3,4,5,6 and Floor 2 → 1,2,3,4,5,6.

3. Floor & Slot Priority

Floors are searched in ascending order; within a floor, slots are scanned in ascending order. The first compatible free slot wins.

4. Parking Lot Full

If no compatible slot is available anywhere, print:

Parking Lot Full

This is per vehicle type — the lot may have free bike slots while car slots are full.

park_vehicle CAR KA-01-DF-8230 black
→ Parking Lot Full

5. Ticket Validation

Invalid ticket

A ticket is valid only when the parking lot ID is valid, the floor exists, the slot exists, and the slot is currently occupied. Otherwise print Invalid Ticket.

6. Ranges and Configuration

create_parking_lot PR1234 3 10
→ 3 floors, 10 slots per floor (1→Truck, 2→Bike, 3→Bike, 4-10→Car)

7. Input Format

Commands
Command
Format
Create
create_parking_lot <id> <floors> <slots-per-floor>
Park
park_vehicle <type> <registration> <color>
Unpark
unpark_vehicle <ticket-id>
Display
display <free_count|free_slots|occupied_slots|registration_numbers_for_cars_with_colour|slot_number_for_registration_number|slot_numbers_for_cars_with_colour> <arg>
Exit
exit

Examples:

create_parking_lot PR1234 2 6
park_vehicle CAR KA-01-DB-1234 black
park_vehicle BIKE KA-01-DB-1541 black
park_vehicle TRUCK KA-32-SJ-5389 orange
unpark_vehicle PR1234_2_5
display free_count CAR
display free_slots BIKE
display occupied_slots TRUCK
display registration_numbers_for_cars_with_colour black
display slot_number_for_registration_number KA-01-DB-1234
display slot_numbers_for_cars_with_colour black

Example Usage: Full Walkthrough

1. Create the Parking Lot

> create_parking_lot PR1234 2 6
Created parking lot with 2 floors and 6 slots per floor
Floor 1: 1→Truck, 2→Bike, 3→Bike, 4→Car, 5→Car, 6→Car
Floor 2: 1→Truck, 2→Bike, 3→Bike, 4→Car, 5→Car, 6→Car

2. Check Initial Car Availability

> display free_count CAR
No. of free slots for CAR on Floor 1: 3
No. of free slots for CAR on Floor 2: 3

3. Park Cars

> park_vehicle CAR KA-01-DB-1234 black
Parked vehicle. Ticket ID: PR1234_1_4

> park_vehicle CAR KA-02-CB-1334 red
Parked vehicle. Ticket ID: PR1234_1_5

> park_vehicle CAR KA-01-DB-1133 black
Parked vehicle. Ticket ID: PR1234_1_6

> park_vehicle CAR KA-05-HJ-8432 white
Parked vehicle. Ticket ID: PR1234_2_4

4. Display Free Car Slots

> display free_slots CAR
Free slots for CAR on Floor 1:
Free slots for CAR on Floor 2: 5,6

5. Remove a Vehicle

> unpark_vehicle PR1234_2_5
Unparked vehicle with Registration Number: WB-45-HO-9032 and Color: white

Slot 5 on Floor 2 is now available.

6. Park Another Car

> park_vehicle CAR KA-21-HS-2347 red
Parked vehicle. Ticket ID: PR1234_2_5

System checks Floor 1 → No free car slot, Floor 2 → Slot 5 available → assigns PR1234_2_5.

7. Park a Bike

> park_vehicle BIKE KA-01-DB-1541 black
Parked vehicle. Ticket ID: PR1234_1_2

8. Park a Truck

> park_vehicle TRUCK KA-32-SJ-5389 orange
Parked vehicle. Ticket ID: PR1234_1_1

> park_vehicle TRUCK KL-12-HF-4542 green
Parking Lot Full

9. Display Occupied Slots

> display occupied_slots CAR
Occupied slots for CAR on Floor 1: 4,5,6
Occupied slots for CAR on Floor 2: 4,5,6

> display occupied_slots BIKE
Occupied slots for BIKE on Floor 1: 2
Occupied slots for BIKE on Floor 2:

10. Invalid Ticket

> unpark_vehicle PR1234_2_5
Invalid Ticket

11. Query by colour and registration

> display registration_numbers_for_cars_with_colour black
KA-01-DB-1234, KA-01-DB-1133

> display slot_numbers_for_cars_with_colour black
4,6

> display slot_number_for_registration_number KA-01-DB-1234
4

> display slot_number_for_registration_number KA-99-XX-0000
Not found

12. Multi-capacity homogeneous spot & nearest-entry

> park_vehicle BIKE KA-01-DB-9991 white
Parked vehicle. Ticket ID: PR1234_1_2  // shares Floor1 Slot2 with KA-01-DB-1541 (2/4)

> park_vehicle BIKE KA-01-DB-9992 white
Parked vehicle. Ticket ID: PR1234_1_2  // 3/4 in same spot

> park_vehicle CAR KA-01-DB-9993 white
Parked vehicle. Ticket ID: PR1234_2_6  // cannot join bike spot — new car spot, nearest to entry

13. Payment on exit (time × category)

> unpark_vehicle PR1234_1_2
Unparked vehicle with Registration Number: KA-01-DB-1541 and Color: white
Duration: 2 hrs — Fee: ₹20 (Bike ₹10/hr)

> unpark_vehicle PR1234_1_4
Unparked vehicle with Registration Number: KA-01-DB-1234 and Color: black
Duration: 3 hrs — Fee: ₹60 (Car ₹20/hr)

Rates are assumptions stated to the reviewer (e.g., Bike ₹10/hr, Car ₹20/hr, Truck/Bus ₹30/hr); the spot frees capacity but remains homogeneous until empty.

Result

The final system creates a parking lot, manages floors and vehicle-specific slots, assigns the nearest suitable spot, generates tickets, handles 1-4 bikes / 1-2 cars / 1 truck per homogeneous spot, answers colour/registration queries, and displays real-time availability plus time-based fees for cars, bikes, and trucks.

What They Looked For

Evaluation criteria
Criterion
What's assessed
Demoable & correct
Code runs and is functionally correct for the sample flow.
Readability
Code is clean and easy to follow.
Entity modelling
Lot, floor, slot, vehicle, and ticket are proper entities — not scattered fields.
Modularity & extensibility
New vehicle types or slot layouts can be added without rewriting the core.
Separation of concerns
Allocation, ticketing, and display stay decoupled.
Edge cases
Parking Lot Full and Invalid Ticket handled gracefully.
Up next1/2
Part 1 · SDE-2+
←
← Prev Chapter
Quick Commerce System
5 min
Next Chapter →
Splitwise
5 min · continue reading
→

Enroll in machine coding mastery series

₹30,000₹3,00090% OFF
Enroll Now →

Use code SOLID50 · 3 years · 40+ lessons

On this page
  • Objective
  • Functional Requirements
    • Part 1 — Basic Requirements
    • Part 2 — Bonus Features
    • Part 3 — Validations & Edge Cases
  • Example Usage: Full Walkthrough
    • 1. Create the Parking Lot
    • 2. Check Initial Car Availability
    • 3. Park Cars
    • 4. Display Free Car Slots
    • 5. Remove a Vehicle
    • 6. Park Another Car
    • 7. Park a Bike
    • 8. Park a Truck
    • 9. Display Occupied Slots
    • 10. Invalid Ticket
    • 11. Query by colour and registration
    • 12. Multi-capacity homogeneous spot & nearest-entry
    • 13. Payment on exit (time × category)
  • What They Looked For