Maximum Matching of Players With Trainers

You are given a 0-indexed integer array players, where players[i] represents the ability of the i^th player. You are also given a 0-indexed integer array trainers, where trainers[j] represents the training capacity of the j^th trainer.

The i^th player can match with the j^th trainer if the player's ability is less than or equal to the trainer's training capacity. Additionally, the i^th player can be matched with at most one trainer, and the j^th trainer can be matched with at most one player.

Return the maximum number of matchings between players and trainers that satisfy these conditions.

Note: This question is the same as 445: Assign Cookies.

Example 1
Inputplayers = [4,7,9], trainers = [8,2,5,8]
Output2
Players 0 and 1 can be matched with trainers 0 and 3 respectively, and it can be proven that 2 is the maximum number of matchings.
Example 2
Inputplayers = [1,1,1], trainers = [10]
Output1
The only trainer can be matched with any one of the 3 players, so the maximum answer is 1.

Constraints

  • 1 <= players.length, trainers.length <= 10^5
  • 1 <= players[i], trainers[j] <= 10^9

Asked at 3 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate