Dsa
Queue
Medium
Customer Service Queue
You are tasked with simulating a customer service queue for a call center. Each customer can either join the queue, be served, or leave without being served. Implement a program that maintains the queue and processes requests based on the following input format:
Input:
- The first line contains an integer n (1 ≤ n ≤ 1000), the number of requests.
- The next n lines contain one of the following commands:
'JOIN <customer_id>' - to join the queue with a unique customer ID.
'SERVE' - to serve the front customer in the queue and remove them.
'LEAVE <customer_id>' - to remove a specific customer from the queue without serving them.
Output:
- Print the customer IDs of the customers served in the order they were served. If the queue is empty when a SERVE command is encountered, print 'No customers in queue'.
Example:
Input:
5
JOIN 101
JOIN 102
SERVE
LEAVE 101
SERVE
Output:
102
Key concepts
queuesimulationdata structure
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