Class Solution
-
- All Implemented Interfaces:
public final class Solution
2410 - Maximum Matching of Players With Trainers\.
Medium
You are given a 0-indexed integer array
players
, whereplayers[i]
represents the ability of the <code>i<sup>th</sup></code> player. You are also given a 0-indexed integer arraytrainers
, wheretrainers[j]
represents the training capacity of the <code>j<sup>th</sup></code> trainer.The <code>i<sup>th</sup></code> player can match with the <code>j<sup>th</sup></code> trainer if the player's ability is less than or equal to the trainer's training capacity. Additionally, the <code>i<sup>th</sup></code> player can be matched with at most one trainer, and the <code>j<sup>th</sup></code> trainer can be matched with at most one player.
Return the maximum number of matchings between
players
andtrainers
that satisfy these conditions.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:
players0 can be matched with trainers0 since 4 <= 8.
players1 can be matched with trainers3 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.
Constraints:
<code>1 <= players.length, trainers.length <= 10<sup>5</sup></code>
<code>1 <= playersi, trainersj<= 10<sup>9</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final Integer
matchPlayersAndTrainers(IntArray players, IntArray trainers)
-
-
Method Detail
-
matchPlayersAndTrainers
final Integer matchPlayersAndTrainers(IntArray players, IntArray trainers)
-
-
-
-