Interview Questions/Coding/Trainer Allocation Sweep

Trainer Allocation Sweep

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Trainer Allocation Sweep

A training platform has candidates and coaches. Each candidate has a required skill level, and each coach has a maximum capacity. One coach can train at most one candidate, and one candidate can be assigned to at most one coach. A candidate can be assigned only if the coach's capacity is greater than or equal to the candidate's requirement. Input Format: You are given arrays players and trainers. Output Format: Return the maximum number of candidates that can be assigned to coaches.

Examples

Example 1
Input:
players = [4, 7, 9]
trainers = [8, 2, 5, 8]
Output:
2

Explanation: After sorting, the valid matches are 4 with 5, 7 with 8. That gives 2 matched trainee(s), so the output is 2.

Approach hint

Look for the state that actually matters after each operation.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp