Time Needed to Buy Tickets
A easy-tier problem at 71% community acceptance, tagged with Array, Queue, Simulation. Reported in interviews at Komprise and 1 others.
Time Needed to Buy Tickets is a queue simulation problem that looks trivial on the surface but trips up candidates who overthink it. You're given an array where each element is the time a person needs to buy a ticket, and you need to track when a specific person (at a given index) finishes. Komprise and X have both asked it. The acceptance rate sits around 71%, which means most people get it right, but the ones who don't usually struggle with how to model the queue behavior correctly. This is the problem where you realize the brute-force simulation is actually the right answer, and that's what StealthCoder surfaces instantly if you second-guess yourself during the live assessment.
Companies that ask "Time Needed to Buy Tickets"
Time Needed to Buy Tickets is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.
Get StealthCoderThe trick here is resisting the urge to optimize. You're simulating a queue where people buy tickets, and if their time requirement is longer than remaining wait, they go to the back of the queue. The obvious approach is to simulate it: process each person, decrement their time, and track when your target person exits. No dynamic programming, no greedy algorithm, no math trick. Most candidates who fail either try to avoid simulation (overthinking), or they implement it with off-by-one errors in tracking which person is at index 0 after rotations. The Array and Queue topics are literal: you track state in an array, process in queue order, and print the elapsed time. StealthCoder handles the simulation bookkeeping for you if you blank on the exact loop logic during your OA.
Pattern tags
You know the problem.
Make sure you actually pass it.
Time Needed to Buy Tickets recycles across companies for a reason. It's easy-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Time Needed to Buy Tickets interview FAQ
Is this really just a simulation, or is there a math formula?+
It's pure simulation. There's no formula. You increment time, process the queue, rotate people to the back if needed, and count when your target person finishes. The 71% acceptance rate reflects that most people catch on once they accept simulation is the answer. Don't hunt for a shortcut that doesn't exist.
What's the most common mistake candidates make?+
Tracking the target person's position after queue rotations. When you move someone to the back, their index changes. Use an object or track (person, time) pairs instead of relying on array indices. That one detail causes most wrong answers.
How does this relate to the Queue topic?+
You're implementing FIFO behavior manually. Each iteration, you process the front person, decrement their time, and push them to the back if they're not done. It's a textbook queue simulation, not a data-structure-specific trick.
What's the time and space complexity?+
Time is O(n * m) where n is the queue size and m is the maximum time value. Space is O(n) for the queue. It's not optimal, but optimal doesn't exist for this problem. The simulation is the solution.
Is this problem still asked at Komprise and X?+
Yes, both companies appear in the historical data. It's a low-friction screening problem: easy to implement, hard to mess up cleanly. Interview loops like it because candidates either understand queues or they don't.
Want the actual problem statement? View "Time Needed to Buy Tickets" on LeetCode →