Multi-level parking system design

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2024-01-12

Problem Statement

Design a Multi-Level Parking System that allows vehicles to enter, park, and exit efficiently. The system should handle parking spot allocation, payment, and vehicle tracking while supporting multiple levels and different vehicle types.


Focus on object-oriented design, class interactions, and service responsibilities.


Functional Requirements (FR)


1.Parking Lot Management
•Multiple levels with rows and parking spots.
•Different spot types: compact, regular, large, handicapped, electric vehicle charging.
2.Vehicle Management
•Support multiple vehicle types: motorcycle, car, bus, truck.
•Track vehicle entry, exit, and location.
3.Parking Allocation
•Assign nearest available spot based on vehicle type.
•Handle reservations or VIP spots (optional).
4.Payment Processing
•Calculate parking fee based on duration, spot type, or special pricing.
•Support multiple payment methods (cash, card, mobile).
5.Entry/Exit Management
•Issue tickets at entry.
•Validate tickets at exit.
6.Notifications & Alerts
•Notify when parking is full.
•Optionally alert for EV charging availability or reserved spots.


Non-Functional Requirements (NFR)


•Scalability – Support multiple levels and thousands of spots.
•Reliability – Accurate tracking of spot availability and vehicles.
•Thread Safety – Handle concurrent vehicle entries/exits.
•Extensibility – Easy to add new vehicle types or spot types.


Core Entities & Attributes


Class Key Attributes / Methods

ParkingLot lotId, levels[], totalCapacity, availableSpots(), getAvailableSpot(vehicleType)

Level levelId, rows[], spots[], getAvailableSpot(vehicleType)

Row rowId, spots[]

ParkingSpot spotId, type (compact/large/EV), isOccupied, vehicleId, assignVehicle(vehicle), removeVehicle()

Vehicle vehicleId, type (car/motorcycle/bus), licensePlate

Ticket ticketId, vehicleId, spotId, entryTime, exitTime, amountPaid

Payment paymentId, ticketId, amount, method, status, processPayment()


Service Layer / APIs


•parkVehicle(vehicle) → Assigns nearest available spot and issues ticket.
•exitVehicle(ticketId, paymentMethod) → Processes payment and frees spot.
•getAvailableSpots(levelId, vehicleType) → Returns count of available spots.
•reserveSpot(levelId, spotType) → Optional reservation.
•getParkingStatus() → Returns occupancy per level/row.


Design Considerations


1.Spot Allocation Strategy
•Nearest first, or based on level preference.
•Handle special spots for EV, handicapped, or reserved vehicles.
2.Data Structures
•Min-heap or TreeSet for available spots per type to quickly find nearest spot.
•Maps for vehicleId → spot and ticketId → vehicle mapping.
3.Concurrency
•Thread-safe spot assignment and release.
•Prevent double allocation in concurrent scenarios.
4.Design Patterns
•Strategy for different spot allocation algorithms.
•Observer for occupancy notifications.
•Singleton for ParkingLot instance.
5.Trade-offs
•Allocation speed vs optimal spot selection.
•Memory usage for maintaining free spot data structures.


✅ This LLD problem tests:


•OOP and class design skills
•Service interactions for parking allocation and payments
•Concurrency handling for multiple vehicle entries/exits
•Extensibility for spot types and allocation strategies


Solution

Comments