Given a queue of people and the number of tickets each person needs, return the total time for person k to finish buying tickets. Pattern focus: Queue for Task Simulation. Process the queue in rounds and stop when the target person completes all of their tickets.
tickets = tickets needed by each person, k = target index
time until person k finishes buying tickets
Example 1:
Input:
tickets = [2,3,2] k = 2
Output:
6
Explanation:
The target person finishes after six time units.
Example 2:
Input:
tickets = [5,1,1,1] k = 0
Output:
8
Explanation:
The queue cycles until the first person completes their tickets.