Dsa
Queue
Warm-up
The VIP Fast-Pass
A theme park ride has a queue. Normally, people join at the end (PUSH). However, guests with a 'VIP' pass can jump to the very front of the current line. If multiple VIPs arrive, the latest VIP goes to the front (ahead of previous VIPs). Given a series of arrivals, print the final order in which guests will board the ride.
Example:
Input:
4
PUSH Alice
PUSH Bob
VIP Charlie
PUSH Dave
Output: Charlie,Alice,Bob,Dave
Key concepts
queuepriority insertion
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