InterviewDB
Question
Customer Service Scheduler: Assign Support Tickets to Available Agents
phone
Question Details
Problem
You have n support agents and a stream of incoming tickets. Each ticket has a priority (1-5, higher is more urgent) and an estimated handle time. Agents take one ticket at a time. Assign each incoming ticket to the agent who will be free soonest; break ties by agent index. Simulate the schedule and return the finish time of the last ticket.
python
def schedule_tickets(
n_agents: int,
tickets: list[tuple[int, int]] # (priority, handle_time)
) -> int:
"""Return the timestamp when the last ticket finishes."""
pass
**Input**: n_agents=2, tickets=[(5,3),(3,5),(4,2),(2,4)]
**Output**: 9
# t=0: Agent0 takes ticket0 (free at 3), Agent1 takes ticket1 (free at 5)
# t=3: Agent0 free, takes ticket2 (free at 5)
# t=5: Agent0 and Agent1 both free, Agent0 takes ticket3 (free at 9)
# Last finish: 9
Follow-ups
- How does a min-heap on
(free_time, agent_id)efficiently find the next available agent? - Should priority affect which ticket is assigned next, or which ticket each agent picks up? Explain your design choice.
- How would you modify the simulation to support ticket escalation if wait time exceeds a threshold?
- Extend to agents with different skill sets where only certain agents can handle certain ticket categories.
Full Details
Problem
You have n support agents and a stream of incoming tickets. Each ticket has a priority (1-5, higher is more urgent) and an estimated handle time. Agents take one ticket at a time. Assign each incoming ticket to the agent who will be free soonest; break ties by agent index. Simulate the schedule and return the finish time of the last ticket.
python
def schedule_tickets(
n_agents: int,
tickets: list[tuple[int, int]] # (priority, handle_time)
) -> int:
"""Return the timestamp when the last ticket finishes."""
pass
**Input**: n_agents=2, tickets=[(5,3),(3,5),(4,2),(2,4)]
**Output**: 9
# t=0: Agent0 takes ticket0 (free at 3), Agent1 takes ticket1 (free at 5)
# t=3: Agent0 free, takes ticket2 (free at 5)
# t=5: Agent0 and Agent1 both free, Agent0 takes ticket3 (free at 9)
# Last finish: 9
Follow-ups
- How does a min-heap on
(free_time, agent_id)efficiently find the next available agent? - Should priority affect which ticket is assigned next, or which ticket each agent picks up? Explain your design choice.
- How would you modify the simulation to support ticket escalation if wait time exceeds a threshold?
- Extend to agents with different skill sets where only certain agents can handle certain ticket categories.
Free preview. Unlock all questions →
Topics
Coding
Onsite
Phone