tickets = [3, 2, 4]
k = 15Each person buys one ticket per second. If they need more, they join the back; otherwise they leave. Return the seconds until the person originally at index k finishes. Keep their original identity even as the line moves.
tickets = [3, 2, 4]
k = 15People 0, 1, 2, 0, 1 buy tickets. Person 1 finishes at second 5, so stop before person 2 buys again.
tickets = [5, 1, 1, 1]
k = 08After everyone else leaves, person 0 continues alone and finishes at second 8.
The task allows 1 to 100 people, each needing 1 to 100 tickets. The interactive demo uses smaller limits to keep the trace readable.
LeetCode 2073 ↗tickets = [3, 2, 4] k = 1 → 5
Here n is the number of people and T is the purchases made before k finishes. Setup takes O(n); each deque purchase takes O(1).
The copied counts and queue both use space proportional to the number of people.
tickets = [3, 2, 4] k = 1 → 5
Counting avoids repeated purchases: one pass gives the same answer, even when ticket counts are large.
Visit each person once, regardless of how many tickets they need.
Only a few counters are used. Neither approach changes the original input.