Dsa
Queue
Easy
The Fading Line
A queue of people is waiting for service. Each person has a unique ID and a 'patience' value. When the person at the front of the line is served, they are removed from the queue. Immediately after, every remaining person in the line has their patience value decreased by 1. If a person's patience reaches 0, they immediately leave the line in frustration before the next person is served. This process repeats until the queue is empty. Return the IDs of the people in the order they were successfully served.
Input Format:
A single line of space-separated strings in the format ID:Patience (e.g., 'A:3 B:2 C:2').
Output Format:
A single line of space-separated IDs of the people served.
Example:
Input: A:3 B:2 C:1
Output: A B
Explanation: A is served first. B's patience drops to 1, C's drops to 0. C leaves. Next, B is served. Output: A B.
Key concepts
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