#2073

Time Needed to Buy Tickets

newbie · 265 · lc easy +19 · 72.2% accepted · 1,892 likes · top 81%

Description

n people queue to buy tickets; person i wants tickets[i] tickets. Each person buys one ticket per second, then goes to the back of the line (if they still need more). A person leaves once they finish. Return the number of seconds until the person at position k (0-indexed) finishes buying all their tickets.

Code

1
2
3