Time Needed to Buy Tickets
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
People stand in a line indexed from 0 (front) to n - 1 (back). Person i wants to buy tickets[i] tickets.
Buying one ticket takes exactly one second, and a person can buy only one ticket per turn. After buying, a person who still needs more goes to the back of the line instantly; a person with no tickets left leaves.
Return the number of seconds until the person originally at position k has bought all of their tickets. Try to avoid simulating the queue.
Examples
Constraints
- n == tickets.length
- 1 <= n <= 100
- 1 <= tickets[i] <= 100
- 0 <= k < n
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.