Parking Lot

Level: Intermediate 30–60 min

Concepts: DesignState


Create a program to manage a parking lot system with different types of vehicles and parking spots.

Requirements

  1. Implement parking lot management:
    • Different types of vehicles (Motorcycle, Car, Bus)
    • Different types of parking spots (Motorcycle, Compact, Large)
    • Parking rules based on vehicle and spot types
    • Track available spots and parked vehicles
  2. Handle parking operations:
    • Park a vehicle (assign to appropriate spot)
    • Remove a vehicle (free up spot)
    • Check parking status
    • Find available spots
  3. Return appropriate results:
    • Success/failure of parking operations
    • Current parking lot status
    • Error messages for invalid operations

Test Cases

ScenarioInputExpected ResultNotes
Empty LotCheck statusAll spots availableInitial state
Park MotorcyclePark motorcycle in motorcycle spotSuccessFits in any spot
Park CarPark car in compact spotSuccessFits in compact or large
Park BusPark bus in large spotSuccessNeeds 5 consecutive large spots
Invalid ParkPark car in motorcycle spotErrorSpot too small
Remove VehicleRemove parked vehicleSuccessFrees up spot

Edge Cases to Consider

  • Parking lot is full
  • Vehicle already parked
  • Removing non-existent vehicle
  • Parking in occupied spot
  • Multiple vehicles of same type

Tips

  • Start with basic vehicle and spot types
  • Add parking rules next
  • Then implement spot management
  • Finally add status tracking
  • Consider using enums for vehicle and spot types