Dsa
Queue
Medium
Check Pending Orders
You are managing a queue of customer orders at a restaurant. Each order has a unique order ID and a preparation time in minutes. Customers can check the status of their orders either by their order ID or by viewing the next order to be processed in the queue. Implement a function to manage and simulate this order queue.
Input:
The first line contains an integer Q, the number of operations.
Each of the next Q lines will contain one of the following:
- 'ADD orderID preparationTime' to add an order (1 <= preparationTime <= 60)
- 'CHECK NEXT' to check the next order ready to be processed.
- 'CHECK orderID' to check the specific order.
Output:
For each 'CHECK' operation, print the order status:
- For 'CHECK NEXT', print 'Next Order: {orderID}' or 'No Pending Orders' if the queue is empty.
- For 'CHECK orderID', print 'Order {orderID} is being prepared in {remainingTime} minutes' or 'Order {orderID} not found' if the order does not exist.
Example:
Input:
5
ADD 123 10
ADD 456 15
CHECK NEXT
CHECK 123
CHECK 999
Output:
Next Order: 123
Order 123 is being prepared in 10 minutes
Order 999 not found
Key concepts
queuefifosimulation
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