Design a Parking Lot System
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2024-03-04
Problem Statement
Design and implement a Parking Lot System that manages parking spots for different vehicle types, handles ticketing, and calculates parking fees efficiently.
Functional Requirements (FR)
Vehicle Parking
•Support multiple vehicle types: Car, Bike, Truck, etc.
•Assign the nearest available spot to a vehicle.
•Handle different spot sizes (compact, medium, large).
Ticketing System
•Generate a parking ticket when a vehicle enters.
•Ticket should contain vehicle number, spot ID, entry timestamp.
•When vehicle exits, calculate duration and generate bill/receipt.
Fee Calculation
•Different rates based on vehicle type and duration.
•Configurable fee rules.
Parking Management
•Track free/occupied spots.
•Prevent double assignment.
•Handle full lot scenario with proper error.
Admin Features (Optional/Advanced)
•Add/remove parking floors or spots dynamically.
•Get real-time statistics: occupancy, revenue, spot availability.
Non-Functional Requirements (NFR)
•Scalability → Should support multiple floors and thousands of spots.
•Extensibility → Easy to add new vehicle types or pricing strategies.
•Low Latency → Spot allocation and ticketing should be fast (O(1) or O(log n)).
•Reliability → No two vehicles should be assigned the same spot.
Core Classes & Entities
ParkingLot
•Contains multiple floors and manages overall operations.
ParkingFloor
•Holds multiple parking spots.
ParkingSpot
•Attributes: spotId, size, isFree.
Vehicle
•Attributes: vehicleNumber, type.
Ticket
•Attributes: ticketId, vehicle, spot, entryTime.
Payment/Receipt
•Attributes: ticketId, amount, exitTime.
ParkingManager
•Handles allocation, ticket generation, and payments.
APIs / Methods
•Ticket parkVehicle(Vehicle v)
•void unparkVehicle(Ticket ticket)
•double calculateFee(Ticket ticket)
•List<ParkingSpot> getAvailableSpots(VehicleType type)
Design Decisions
•Spot Allocation Strategy → Nearest available spot (min-heap or queue per type).
•Pricing Strategy → Strategy Pattern for flexible fee calculation.
•Scalability → Use hash maps to track available spots quickly.
•Thread Safety → Synchronize spot allocation if multiple entry gates exist.
✅ This LLD problem evaluates OOP design, extensibility, object relationships, and real-world system modeling.