solidcodersolidcoder
Explore Courses
solidcodersolidcoder

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

Company-wise Questions

  • Flipkart 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/Machine coding Tutorial/Design a Parking Lot System
Chapters — Machine coding Tutorial▾

Design a Parking Lot System

Machine Coding·Machine Coding Questions·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
Slot 1
Truck
Slot 2
Bike
Slot 3
Bike
Slot 4 onwards
Car

For example, with 6 slots:

Floor 1

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

The same layout is repeated for every floor. Slots on each floor are numbered sequentially starting from 1.

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.

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.
3. Compatible type
Slot type must match vehicle type.
4. Available
Slot must be free.

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 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.

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

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.
Multiple Parking Lots
Support more than one parking lot and allow vehicles to be parked in a selected lot.
Vehicle Search
Find the current floor and slot of a vehicle using its registration number.
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.

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> <type>
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

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
Result

The final system creates a parking lot, manages floors and vehicle-specific slots, assigns the first suitable slot, generates tickets, releases slots on exit, and displays real-time availability 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 next6/8
Part 2 · Machine Coding Questions
←
← Prev Chapter
Splitwise
5 min
Next Chapter →
Message Queue
5 min · continue reading
→
This month's launch price
₹30,000₹3,000SOLID50 — 50% OFF

3 years access · 40+ lessons · AI assisted coding

Enroll Now →

Use code SOLID50 at checkout

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
  • What They Looked For