Parking Lot

Design a parking system.

Purposefully vague. Discuss the exact requirement with your interviewer.

Some questions we can ask:

  • How should accessibility be taken care of? Do we need to prioritize handcap parking areas, for example?

  • Is this a ground parking lot, or a monitored system?

  • How many entrances are in the parking lot? (Do we have to deal with any issues of concurancy?)

  • Should there by any pricing strategies in place? Do we offer premium services (reserved parking areas) to customers?

  • Do we need to support different types of spots for different type of vehicles?

Assumptions:

  • Design a monitored system for support for 4 different type of vehicles (S,M,L,XL). The parking lot supports 150 small vehicles, 100 medium vehicles, 50 large vehicles, and 25 extra large vehicles.

  • A smaller vehicle can only be parked in a spot that is designated to be equal or large than itself. That is a L vehicle cannot park to M spot, but can park to an L to XL spot.

Implementation:

  • Build an interface and support efficient implementation for the following methods:

    • Spot placeVehicle(Vehicle):return a spot for a Vehicle spot.

      • This method must return an available spot prioritized by its type. For example, a small vehicle can only be parked in a mediumed sized parking spot iff there are no small vehicle spots available.

      • If there are no spots available, throw an exception.

    • void removeVehicle(Vehicle): remove a vehicle from the parking lot.

Testing

Output

Last updated

Was this helpful?