# Time Needed to Buy Tickets (LeetCode 2073) Simulate queue until person k finishes. ## Approach ```python def timeRequiredToBuy(tickets, k): t = 0 for i, x in enumerate(tickets): if i <= k: t += min(x, tickets[k]) else: t += min(x, tickets[k]-1) return t ``` ## Complexity - Time / space depend on the scan above; keep the solution linear when possible. ## Interview tip Narrate the invariant before coding. I drill these patterns with [try it free](https://www.linkjob.ai/) ahead of OA rounds. *Disclosure: I work on Linkjob AI, an interview copilot. The algorithm above stands on its own.*