Seconds Until a Given Fan Finishes Buying Concert Tickets in Line

Last updated: November 29, 2026

Quick Overview

Fans stand in a line where fan i wants tickets[i] tickets. Each second the front fan buys one ticket and, if they still need more, walks to the back. Return how many seconds pass until fan k has all their tickets.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Fans stand in a line where fan i wants tickets[i] tickets. Each second the front fan buys one ticket and, if they still need more, walks to the back. Return how many seconds pass until fan k has all their tickets.

A Google phone screen opener that starts as a queue simulation and is really about spotting the closed form. The interviewer expects you to code the deque version quickly, then reason about how many tickets each other fan buys before fan k is done.

What the Interviewer Expects
  • Write a correct deque simulation first
  • Notice fans before k buy at most tickets[k], fans after k at most tickets[k] - 1
  • Derive the O(n) formula and justify it
  • Compare O(sum of tickets) versus O(n) running time
  • Confirm k is zero-based
Key Topics to Cover
queue simulation
deque
closed-form reasoning
counting
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you answer many queries for different k quickly?
  • What if each fan could buy up to two tickets per turn?
  • How would you output the full finish order of all fans?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: list tickets of positive ints and index k. One purchase takes one second. A fan with remaining demand rejoins at the back; a satisfied fan leaves. Output the time at which fan k makes the...

High-Level Design

The direct simulation keeps a deque of (index, remaining) and ticks until fan k hits zero; it costs O(sum of tickets). Better: by the time fan k buys their last ticket, every fan in front of them (i...


Submit Your Answer
Markdown supported