Problem · Hash Table
Worker Task Assignment Part 1 - Balance Workload
Learn this problemProblem statement
You assign support tasks to workers, balancing total workload. You are given workers (a String[] of worker names) and tasks (a String[] where each entry is "id,duration" with an integer duration).
Process the tasks in order. Assign each task to the worker who currently has the lowest total workload (sum of durations assigned so far). Break ties by choosing the worker who appears earlier in the workers list. After assigning, add the task's duration to that worker's total.
Return the assignments in task order as a String[], each entry formatted "taskId:worker".
Function
assignTasks(workers: String[], tasks: String[]) → String[]Examples
Example 1
workers = ["alice", "bob", "charlie"]tasks = ["task1,5", "task2,3", "task3,7", "task4,2", "task5,4"]return = ["task1:alice", "task2:bob", "task3:charlie", "task4:bob", "task5:alice"]All at 0 -> task1 to alice (first). alice5,bob0,charlie0 -> task2 to bob (first of the two 0s). alice5,bob3,charlie0 -> task3 to charlie (lowest). alice5,bob3,charlie7 -> task4 to bob (3 is lowest). alice5,bob5,charlie7 -> task5 to alice (tied with bob at 5, alice is first).
Example 2
workers = ["solo"]tasks = ["t1,1", "t2,9"]return = ["t1:solo", "t2:solo"]With a single worker, every task goes to that worker.
Constraints
workersis a list of distinct names;tasksentries are"id,duration"with integer durations.- Assign each task in order to the lowest-current-workload worker; ties go to the earlier worker in the list.
- Add the task's duration to the chosen worker's total after assigning.
- Return assignments in task order as
"taskId:worker".
More Stripe problems
- Group Linked Merchant RecordsPHONE SCREEN · Seen Jul 2026
- Invoice / Payment ReconciliationPHONE SCREEN · Seen Jul 2026
- Incident MonitorOA · Seen Jul 2026
- Merchant Fraud Risk ScoringOA · Seen Jul 2026
- WebSocket Load Balancer — Basic Load Balancing (Part 1)OA · Seen Jul 2026
- Rule-Driven Transaction Fraud DetectionOA · PHONE SCREEN · Seen Jul 2026
- Deployment Window SchedulerOA · Seen Jul 2026
- Directly Linked UsersOA · Seen Jun 2026