Skip to the code
cf.
+10 XP

#259 Checkout Line Wait Time

easy

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.

Example 1

Input: tickets = [2,3,2], k = 2
Output: 6

Round one takes 3 seconds; in round two, person 2 finishes on the 6th second.

Example 2

Input: tickets = [5,1,1,1], k = 0
Output: 8

The others finish in round one; then person 0 needs four more rounds alone.

Constraints

  • 1 <= tickets.length <= 100
  • 1 <= tickets[i] <= 100
  • 0 <= k < tickets.length
Saved in this browser

Run 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).