Preparing your design workspace

Loading the problem and your saved attempt…

Design a Constant-Time Parking Lot

Model a one-row parking lot where parking, parking in a requested spot, leaving and finding a car all take constant time.

For this exercise, assume a parking lot has one row of N spots, numbered 0 to N - 1, where N is fixed when the lot opens and can be as large as 100,000. Every spot fits one car, and each car has a unique plate number.

The lot supports four operations: park a car in any free spot and report the spot number; park a car in one requested spot, for example a spot near the door; let a parked car leave, which frees its spot; and find the spot number of a parked car.

Each operation must take constant time, no matter how large the lot is or how many cars are parked. A request is refused, with a clear reason and no change, when the lot is full, the car is already parked, the requested spot is taken or does not exist, or the car to remove or find is not parked.

Design the objects, their responsibilities, the interfaces, and the interactions, and explain which data structures give constant time. No code is needed. One follow-up adds a second spot size. Payments, tickets, gates, several floors, and reservations ahead of time are out of scope. Everything runs on one thread.