Average Customer Wait With K Support Agents and a FIFO Queue
Last updated: November 29, 2026
Quick Overview
Customers contacting Google One support arrive at given times with known handling durations. There are k agents; an arriving customer goes to the lowest-numbered idle agent, otherwise waits in a first-in first-out queue for the first agent to become free. Return each customer's assigned agent and the average wait time.
0
0
0 solved
Customers contacting Google One support arrive at given times with known handling durations. There are k agents; an arriving customer goes to the lowest-numbered idle agent, otherwise waits in a first-in first-out queue for the first agent to become free. Return each customer's assigned agent and the average wait time.
A Google technical screen discrete event simulation. The interviewer checks that you separate idle and busy agents correctly so tie-breaking by agent id holds, and that you argue why processing customers in arrival order is valid for a FIFO queue.
What the Interviewer Expects
- Use a min-heap of idle agent ids and a min-heap of (free_time, id) for busy agents
- Release every busy agent whose free time is at or before the arrival
- Assign the lowest idle id, or the earliest-freeing agent when none is idle
- Argue that FIFO start times are non-decreasing, so arrival order processing is correct
- Compute waits as start minus arrival
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you compute the 95th percentile wait instead of the average?
- What if customers abandon after waiting longer than a patience limit?
- How would you choose k to keep the average wait under one minute?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of (arrival, duration) sorted by arrival, and k >= 1. An agent freed at time t can take a customer arriving at t. If several agents free up at the same time and someone is waiting, the...
High-Level Design
Keep idle (min-heap of ids) and busy (min-heap of (free_time, id)). For each customer at time a: pop every busy agent with free_time <= a into idle. If idle is non-empty, take the smalle...