#2410
Maximum Matching of Players With Trainers
pupil · 490 · lc medium +27 · verified · 75.2% accepted · 921 likes · top 86%
Description
You are given a 0-indexed integer array players (player skill levels) and a 0-indexed integer array trainers (trainer capacity levels).
A player and a trainer are compatible when the player's level does not exceed the trainer's capacity. Each player and trainer can be matched at most once.
Return the maximum number of compatible player–trainer pairs.
Example 1:
Input: players = [4,7,9], trainers = [8,2,5,8]
Output: 2
Explanation:
One of the ways we can form two matchings is as follows:
- players[0] can be matched with trainers[0] since 4 <= 8.
- players[1] can be matched with trainers[3] since 7 <= 8.
It can be proven that 2 is the maximum number of matchings that can be formed.
Example 2:
Input: players = [1,1,1], trainers = [10]
Output: 1
Explanation:
The trainer can be matched with any of the 3 players.
Each player can only be matched with one trainer, so the maximum answer is 1.
Code
1
2
3