17 · Queues & Deques

#2073 Time Needed to Buy Tickets

Easysolve on LeetCode ↗

frequently reported atGoogleAmazon

the problem

In plain words

People stand in a line; person i wants tickets[i] tickets. Each second the front person buys one ticket and, if they still need more, goes to the back of the line. How many seconds until person k has all their tickets?

in tickets = [2,3,2], k = 2

out 6

in tickets = [5,1,1,1], k = 0

out 8

  • 1 ≤ n ≤ 100
  • 1 ≤ tickets[i] ≤ 100
  • 0 ≤ k < n

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #950
    2. #933