Tap here to switch tabs
Problem
Submissions

Problem: Time Needed to Buy Tickets

med
30 min
Try to solve the Time Needed to Buy Tickets problem.

Statement

You are given an integer array tickets where tickets[i] is the number of tickets the iith person in a queue wants to buy. The queue is processed in rounds as follows.

At each second, the person at the front of the queue buys exactly one ticket, decreasing their remaining count by 11. If they still need more tickets, they move to the back of the queue. Otherwise, they leave the queue.

Given an index k, return the total number of seconds required until the person who initially starts at position k has purchased all of their tickets.

Note: The index k refers to the person’s original position in the initial queue.

Constraints:

  • ‘n‘==‘tickets.length‘`n` == `tickets.length`

  • 1≤‘n‘≤1001 \leq `n` \leq 100

  • 1≤‘tickets[i]‘≤1001 \leq `tickets[i]` \leq 100

  • 0≤‘k‘<‘n‘0 \leq `k` < `n`

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Time Needed to Buy Tickets

med
30 min
Try to solve the Time Needed to Buy Tickets problem.

Statement

You are given an integer array tickets where tickets[i] is the number of tickets the iith person in a queue wants to buy. The queue is processed in rounds as follows.

At each second, the person at the front of the queue buys exactly one ticket, decreasing their remaining count by 11. If they still need more tickets, they move to the back of the queue. Otherwise, they leave the queue.

Given an index k, return the total number of seconds required until the person who initially starts at position k has purchased all of their tickets.

Note: The index k refers to the person’s original position in the initial queue.

Constraints:

  • ‘n‘==‘tickets.length‘`n` == `tickets.length`

  • 1≤‘n‘≤1001 \leq `n` \leq 100

  • 1≤‘tickets[i]‘≤1001 \leq `tickets[i]` \leq 100

  • 0≤‘k‘<‘n‘0 \leq `k` < `n`