Dsa
Heap
Hard
Parking Lot System
Design a parking lot system that can track the availability of parking spaces based on arrival and departure events. You will receive a series of events where each event is either an arrival or a departure, along with the ID of the vehicle. Use a min-heap to track the available spaces and ensure that when a vehicle departs, that space becomes available again. The first line contains the number of parking spaces. Subsequent lines will contain events in the format 'arrive <vehicle_id>' or 'depart <vehicle_id>'. Output the ID of the vehicle that has departed once the departure event is processed. If a vehicle arrives but there are no spaces, print 'No available space'. The last input line contains a '-' to signal the end of inputs.
Example:
Input:
5
arrive 101
depart 101
arrive 102
-
Output:
101
Key concepts
heappriority queuesimulation
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now