Question bank › Queue
Dsa Queue Medium

Track Train Departures

You are implementing a system to track train departures from a station. Each train may depart at a specific time, and you need to maintain the order of departures. Implement a program according to the following input format: Input: - The first line contains an integer n (1 ≤ n ≤ 1000), the total number of train departure requests. - The next n lines will either be 'ARRIVE <train_id> <departure_time>' or 'DEPART'. <train_id> is a unique identifier and <departure_time> is a string (in 24-hour format) representing when the train should depart. Output: - Print the train IDs in the order they departed. If a DEPART command is encountered but no trains are ready to depart, print 'No trains to depart'. Example: Input: 5 ARRIVE A1 13:00 ARRIVE A2 14:30 DEPART ARRIVE A3 13:30 DEPART Output: A1 A3

Key concepts

queueevent-drivensimulation

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.