All practice tasks

Coding (Algo)

Compatible Worker Assignment

Bipartite matching · Hard

Each waiting job can run only on certain workers because of capabilities. Assigning the first available worker greedily can leave avoidable idle capacity.

Return the maximum number of jobs that can run at once with one job per worker.

Input

Call

  • Implement solve(input) and return its result. Do not print from solve.

Input object

{ workers:integer, eligible:integer[][] }. eligible[i] lists worker IDs that can execute job i; repeated IDs are allowed

What each field means

  • workers — number of workers with IDs 0 through workers - 1.
  • eligible[i] — worker IDs allowed to execute job i; duplicate IDs have no extra effect.

Output

Return value and rules

  • Return the maximum number of jobs that can run simultaneously.
  • Assign each job to at most one eligible worker and each worker to at most one job.
  • Return only the count, not a particular assignment.

Constraints

  • 0 <= workers <= 200; 0 <= eligible.length <= 200
  • Worker IDs are in [0,workers-1]; each eligible list contains at most 200 entries.

Examples

Example 1

{
  "eligible": [
    [
      0,
      1
    ],
    [
      0
    ]
  ],
  "workers": 2
}

Returns

2

Example 2

{
  "eligible": [],
  "workers": 0
}

Returns

0

Required complexity

O(jobs × eligibilityEdges) time and O(workers + jobs) auxiliary space

What this task practices

Compatible Worker Assignment is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as hard difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.