Dsa
Queue
Warm-up
Train Car Queue
You are asked to simulate the loading and unloading of train cars at a station. The station can load cars in order and unload cars from the front of the queue. You will receive commands in the form of 'load <car_id>' to load a train car or 'unload' to unload the car at the front of the queue. If you attempt to unload when there are no cars, you should print 'No cars in the station.'
Input format:
- The first line contains an integer k (1 <= k <= 100) indicating the number of commands.
- The next k lines contain the commands as described above.
Output format:
- For each unload command, print either the id of the car being unloaded or a message if the station is empty.
Example:
Input:
4
load 101
load 102
unload
unload
Output:
Loaded car: 101
Loaded car: 102
Unloading car: 101
Unloading car: 102
Key concepts
queuelistsimulation
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