Dsa
Queue
Easy
Library Book Reservation Queue
You are developing a library system where users can reserve books. When a book is reserved, users are placed in a queue until the book is available. Your system should handle the following commands:
1. `RESERVE USERNAME` - A user with `USERNAME` reserves a book.
2. `FILL` - Fill the reservation for the user at the front of the queue and print their username. If the queue is empty, print 'No reservations to fill.'
3. `STATUS` - Output the number of users currently waiting in the reservation queue.
4. `NEXT` - Print the username of the next user in line without removing them from the queue. If the queue is empty, print 'No users in queue.'
Example Input:
RESERVE Alice
RESERVE Bob
STATUS
FILL
STATUS
NEXT
FILL
FILL
Example Output:
2
Alice
1
No reservations to fill.
Key concepts
queuelibraryreservation
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