Dsa
Queue
Easy
Office Hours Round-Robin
A TA is holding office hours. There is a single queue of students. Each student has a name and a required time (minutes) to resolve their issue. The TA uses a round-robin approach with a time slice of K minutes. If a student's issue is not resolved within K minutes, they go back to the end of the queue. If it is resolved, they leave.
Input: The first line contains K (the time slice) and N (the number of students). The following N lines each contain a student's name and their required time.
Output: Print the name of each student and the total time elapsed when they finally finish, in the order they complete their session.
Example:
Input:
2 2
Alice 5
Bob 2
Output:
Bob 4
Alice 7
Key concepts
queuesimulation
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