Design a parking lot system
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-05-22
Problem Statement
Design an object-oriented parking lot system with the following specifications:
Structure:
1.The parking lot is made up of multiple levels.
2.Each level consists of multiple rows, and each row has multiple parking spots.
3.There are two types of vehicles:
Motorcycle
Car
1.There are two types of parking spots:
Motorcycle Spot
Car Spot
Parking Rules:
1.A motorcycle can park in any available spot (motorcycle or car).
2.A car can only park in a car spot.
3.Parking must follow first-available spot rule based on the vehicle type and availability.
Functional Requirements:
1.park(Vehicle vehicle): Parks the given vehicle in the first suitable available spot (following the parking rules). Returns success or failure.
2.unpark(Vehicle vehicle): Frees up the spot where the given vehicle is parked.
3.search(Vehicle vehicle): Returns the location (level, row, and spot number) of the vehicle if it is parked, or indicate that it's not found.
Design Expectations:
1.Design the classes, interfaces, and relationships involved (e.g., ParkingLot, Level, Row, Spot, Vehicle, Car, Motorcycle).
2.Ensure clean separation of concerns using object-oriented principles.
3.Use appropriate design patterns where necessary (e.g., Strategy for parking rules, Factory for vehicle creation, etc.).
4.Optimize for readability, extensibility (e.g., adding new vehicle types or spot types), and testability.