A ticket site's waiting room lets people buy one ticket at a time. tickets[i] is how many tickets person i wants, and the line starts in index order. Each second, the person at the front buys one ticket. If they still want more, they go to the back of the line; otherwise they leave.
Write secondsUntilDone(tickets, k) that returns how many seconds pass until person k has bought all of their tickets.
Input: tickets = [2,3,2], k = 2 Output: 6
Round one takes 3 seconds; in round two, person 2 finishes on the 6th second.
Input: tickets = [5,1,1,1], k = 0 Output: 8
The others finish in round one; then person 0 needs four more rounds alone.
1 <= tickets.length <= 1001 <= tickets[i] <= 1000 <= k < tickets.lengthRun tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #259 Checkout Line Wait Time. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.