Imagine you're at a movie theater where people queue up to buy tickets, but there's a catch! Each person can only buy one ticket at a time and takes exactly 1 second per purchase. If someone needs multiple tickets, they must go to the back of the line after each purchase.
You're given an array tickets where tickets[i] represents how many tickets the i-th person wants to buy. The person at position 0 is at the front, and position n-1 is at the back.
Your task: Find how long it takes for the person initially at position k to finish buying all their tickets.
Example: If tickets = [2,3,2] and k = 2, we want to know when person 2 (who needs 2 tickets) finishes buying. They start at the back, buy 1 ticket, go to the back again, then buy their final ticket.
Input & Output
Constraints
- n == tickets.length
- 1 โค n โค 100
- 1 โค tickets[i] โค 100
- 0 โค k < n
- All values are positive integers