As reported: Twilio Software Engineer L3 (2026), coding + machine coding round, question 1: people stand in a queue, each holding some coins; every second the person at the front loses one coin, then leaves if out of coins or otherwise goes to the back; given a target person's initial index, find the number of seconds until they run out of coins.
There are n people in a line; person i (0-indexed) starts with tickets[i] coins. Each second, the person at the front spends one coin; if they have coins left they move to the back of the line, otherwise they leave. Return the number of seconds that pass until the person initially at position k has spent all their coins.
This is LeetCode 2073 — Time Needed to Buy Tickets (coins play the role of tickets).
Example 1
tickets = [2,3,2], k = 2 -> 6
Example 2
tickets = [5,1,1,1], k = 0 -> 8
Constraints: 1 ≤ n ≤ 100; 1 ≤ tickets[i] ≤ 100; 0 ≤ k < n.
Code runner format: one JSON value per line (LeetCode's test-case format): tickets, then k. Implement timeRequiredToBuy(tickets, k); the harness prints the number.