Dsa
Heap
Easy
Emergency Room Triage
An emergency room needs an automated triage system. Each patient has a Name, a Severity (1-10, where 1 is most urgent), and an Age. The system must always call the most urgent patient (lowest severity). If severities are tied, the oldest patient is called first. If both severity and age are tied, call the patient whose name comes first alphabetically.
Input Format:
- The first line contains N, the number of operations.
- Each operation is either 'ARRIVE <name> <severity> <age>' or 'NEXT'.
Output Format:
- For each 'NEXT' command, print the name of the patient to be treated. If the ER is empty, print 'IDLE'.
Example:
Input:
5
ARRIVE Alice 3 25
ARRIVE Bob 3 40
ARRIVE Charlie 1 30
NEXT
NEXT
Output:
Charlie
Bob
Key concepts
priority queuesorting
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