Dsa
Queue
Easy
Book Lending Queue
A library has a queue of patrons waiting to borrow books. Each patron has a specified borrowing duration in days. The library can only process one patron at a time and each patron must wait until the previous one is finished. You need to determine the total number of days until all patrons have borrowed their books. Input the number of patrons followed by their respective borrowing durations in days.
Input Format:
- The first line contains an integer N (1 ≤ N ≤ 1000), the number of patrons.
- The next N lines each contain an integer D (1 ≤ D ≤ 30), the borrowing duration for each patron, in days.
Output Format:
- Output a single integer representing the total days taken to serve all patrons.
Example:
Input:
3
2
3
5
Output:
10
Key concepts
queuedata 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