Design parking system

Difficulty: EASYCategory: LLDFrequency: 1Asked On 2024-09-06

Problem Statement

Design a Parking Lot System that can manage the parking of different types of vehicles and support common operations like parking, leaving, and querying availability. The system should be scalable and extensible for real-world use cases (e.g., malls, offices, airports).

🎯 Functional Requirements

1. Vehicle Types Supported

•Car
•Bike
•Truck

2. Operations to Support

•createParkingLot(int numFloors, int slotsPerFloor)
•Initializes the parking structure.
•Each floor has a fixed number of slots.
•Slots may be designated for specific vehicle types.
•parkVehicle(Vehicle vehicle)
•Assigns a parking slot to the vehicle based on availability.
•Returns a Ticket (with slot info, timestamp, etc.) or a failure message if the lot is full.
•unparkVehicle(String ticketId)
•Frees the corresponding parking slot and marks it available.
•Calculates and returns the parking fee based on time.
•getAvailableSlots(VehicleType type)
•Returns the number of available slots for the given vehicle type.
•display()
•Shows a snapshot of current parking status (free/occupied slots, per floor/type).


Solution

Comments