Worker Task Assignment Part 1 - Balance Workload
Updated
Problem 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). alice 5, bob 0, charlie 0 -> task2 to bob (first of the two 0s). alice 5, bob 3, charlie 0 -> task3 to charlie (lowest). alice 5, bob 3, charlie 7 -> task4 to bob (3 is lowest). alice 5, bob 5, charlie 7 -> 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
1 <= workers.length <= 100. Worker names are distinct and have1to20characters: letters, digits and spaces.1 <= tasks.length <= 1000. Each entry is"id,duration":idhas1to20characters and no comma, anddurationis an integer with0 <= duration <= 10^6.- 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 Onsite Interview questions
- Render a Task Tree from CSV RowsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Invoice / Payment ReconciliationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Parse Boolean Rule ExpressionsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Transaction Rule Expression EvaluatorONSITE INTERVIEW · Seen Oct 2026
- Evaluate Ordered Action RulesPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- WebSocket Load Balancer — Parts 1–5OA · ONSITE INTERVIEW · Seen Sep 2026
- Rule-Driven Transaction Fraud DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Account Balance Manager Part 3 - Platform CoverageONSITE INTERVIEW · Seen May 2026
- Account Balance Manager Part 2 - Reject OverdraftsONSITE INTERVIEW · Seen May 2026
- Account Balance Manager Part 1 - Calculate TotalsONSITE INTERVIEW · Seen May 2026
Similar questions at other companies
- Reorganize a StringAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Rearrange a String So No Neighbors MatchThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
- Longest-Match Tokenizer with Unknown SymbolsAnthropic · ONSITE INTERVIEWAnthropic interview questions
- Greedy and Beam Sentence DecodingMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
- Choose the Next Hidden-Word GuessFlexport · ONSITE INTERVIEWFlexport interview questions
- Stable Top K Frequent WordsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Top K Keys from JSON RecordsCapital One · ONSITE INTERVIEWCapital One interview questions
- Minimum Operations to Reduce a Transaction LedgerVisa · OAVisa interview questions
- Find Length of Longest Good SubsequenceWalmart · OAWalmart interview questions
- Design a Food Rating SystemApple · PHONE SCREENApple interview questions