Problem Β· Heap

Worker Assignment β€” Skills and Account Affinity

Learn this problem
● MediumStripe logoStripeINTERNONSITE INTERVIEW
See Stripe hiring insights

Problem statement

Assign support tasks to workers in input order.

Input

  • workers: "name,specialty".
  • tasks: "id,duration,accountId,skills", where skills is a |-separated set of acceptable specialties.

For each task:

  1. Keep workers whose specialty appears in the task's skills.
  2. If any eligible worker has previously handled the same account, restrict candidates to those workers.
  3. Choose the candidate with the lowest accumulated workload; break ties by earlier position in workers.

After assignment, add the task duration to the worker's workload and record that the worker has handled the account. If no worker has a required specialty, skip the task. Return successful assignments as "taskId:worker" in task order.

Practice sequence

  1. Part 1: balance workload
  2. Part 2: add specialties.
  3. Part 3: add account affinity (current).

Function

assignTasksAdvanced(workers: String[], tasks: String[]) β†’ String[]

Examples

Example 1

workers = ["Alice,payments","Bob,risk","Cara,payments"]tasks = ["t1,5,acct1,payments","t2,3,acct2,payments|risk","t3,4,acct1,payments|risk","t4,2,acct3,risk"]return = ["t1:Alice","t2:Bob","t3:Alice","t4:Bob"]
t1 goes to Alice by input-order tie-break. t2 goes to Bob, the lowest-workload eligible worker. For t3, Alice has account affinity and is selected despite a larger workload. t4 requires risk and goes to Bob.

Example 2

workers = ["A,java","B,python"]tasks = ["x,2,c1,ruby","y,1,c1,java|python","z,1,c1,python"]return = ["y:A","z:B"]
x is skipped because no worker has ruby. y ties at zero and chooses A. z requires python, so it goes to B; A's account history cannot override the skill requirement.

Constraints

  • Worker names are unique and every worker has one specialty.
  • Task IDs are unique and durations are non-negative integers.
  • Task skill lists are non-empty and use | as the delimiter.
  • Workers start with workload 0 and no account history.
  • Input order breaks workload ties.
  • A task with no eligible worker is skipped.

More Stripe problems

drafts saved locally
public String[] assignTasksAdvanced(String[] workers, String[] tasks) {
  // write your code here
}
workers["Alice,payments","Bob,risk","Cara,payments"]
tasks["t1,5,acct1,payments","t2,3,acct2,payments|risk","t3,4,acct1,payments|risk","t4,2,acct3,risk"]
expected["t1:Alice", "t2:Bob", "t3:Alice", "t4:Bob"]
checking account