There are n people in a line queuing to buy tickets. The 0th person is at the front, and the (n-1)th person is at the back. An integer array tickets represents the number of tickets each person wants to buy. Each person takes exactly 1 second to buy a ticket and must go back to the end of the line to purchase another if needed. Return the time taken for the person initially at position k to finish buying their tickets.
Click Run to execute sample tests.