Your question is Assign Tasks to Least Busy Agent. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Intercom's inbox assigns incoming conversations to available agents. Given each agent's processing capacity and a sequence of task workloads, assign every task to the agent with the smallest current workload relative to capacity.
An agent's busy time is defined as assigned_workload / capacity. After assigning a task, update that agent's assigned workload. If multiple agents have the same busy time, choose the agent with the smallest index. Tasks are assigned in the order provided, and every task must be assigned exactly once.
Implement assign_tasks(capacities, tasks), where capacities is a list of positive integers and tasks is a list of positive integer workloads. Return a list containing the selected zero-based agent index for each task.
Comparisons must be exact. For example, 2 / 3 must be considered less than 1 / 2 only when mathematically appropriate, rather than based on rounded floating-point values.
def assign_tasks(capacities, tasks):