Design a Multi-Floor Parking Lot
Model compatible parking for bikes, cars and five-spot buses, with atomic ticketed allocation and a nearest-entrance extension.
Design the software for a multi-floor parking lot with Bike, Car and Bus vehicles and Bike, Compact and Large spots. Bikes may use any spot type;cars may use Compact or Large;one bus needs five Large spots.
Explain efficient empty-space lookup and how deliberate bike/car allocation can preserve Large capacity for buses.
For this exercise, assume each floor has fixed, numbered spots in a linear order, and the five bus spots must be consecutive on one floor. Adjacency and same-floor placement are practice assumptions.
A successful park atomically reserves the complete compatible group and issues one immutable ticket;one vehicle has at most one active ticket. No-compatible-space or duplicate active vehicle rejects without mutation.
Closing a ticket releases its whole group once;already-closed tickets are harmless no-ops, and an unknown ticket changes nothing. Concurrent entrance requests must never create overlapping allocations or partial bus tickets.
Design the objects, contracts and interaction trace. No implementation code is required. Explain a deterministic allocation policy that considers scarce Large runs, and state honest lookup/update costs in S total spots and H retained ticket records;optimal utilization for unknown future arrivals is not required.
Pricing, payments, reservations, persistence and UI are excluded.
For the existing multiple-entrance follow-up, choose the closest appropriate available single spot or bus group. For this exercise, an entrance supplies distance to the candidate’s first spot.
Consider all valid group starts, keep authoritative allocation/release unchanged, and explain the closest-versus-future-capacity trade-off and deterministic ties.