2410. Maximum Matching of Players With Trainers LeetCode Solution
In this guide, you will get 2410. Maximum Matching of Players With Trainers LeetCode Solution with the best time and space complexity. The solution to Maximum Matching of Players With Trainers problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.
Table of Contents
- Problem Statement
- Complexity Analysis
- Maximum Matching of Players With Trainers solution in C++
- Maximum Matching of Players With Trainers solution in Java
- Maximum Matching of Players With Trainers solution in Python
- Additional Resources

Problem Statement of Maximum Matching of Players With Trainers
You are given a 0-indexed integer array players, where players[i] represents the ability of the ith player. You are also given a 0-indexed integer array trainers, where trainers[j] represents the training capacity of the jth trainer.
The ith player can match with the jth trainer if the player’s ability is less than or equal to the trainer’s training capacity. Additionally, the ith player can be matched with at most one trainer, and the jth trainer can be matched with at most one player.
Return the maximum number of matchings between players and trainers 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:
– 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.
Constraints:
1 <= players.length, trainers.length <= 105
1 <= players[i], trainers[j] <= 109
Note: This question is the same as 445: Assign Cookies.
Complexity Analysis
- Time Complexity: O(\texttt{sort})
- Space Complexity: O(\texttt{sort})
2410. Maximum Matching of Players With Trainers LeetCode Solution in C++
class Solution {
public:
int matchPlayersAndTrainers(vector<int>& players, vector<int>& trainers) {
int ans = 0;
ranges::sort(players);
ranges::sort(trainers);
for (int i = 0; i < trainers.size(); ++i)
if (players[ans] <= trainers[i] && ++ans == players.size())
return ans;
return ans;
}
};
/* code provided by PROGIEZ */
2410. Maximum Matching of Players With Trainers LeetCode Solution in Java
class Solution {
public int matchPlayersAndTrainers(int[] players, int[] trainers) {
int ans = 0;
Arrays.sort(players);
Arrays.sort(trainers);
for (int i = 0; i < trainers.length; ++i)
if (players[ans] <= trainers[i] && ++ans == players.length)
return ans;
return ans;
}
}
// code provided by PROGIEZ
2410. Maximum Matching of Players With Trainers LeetCode Solution in Python
class Solution:
def matchPlayersAndTrainers(
self,
players: list[int],
trainers: list[int],
) -> int:
ans = 0
players.sort()
trainers.sort()
for i, trainer in enumerate(trainers):
if players[ans] <= trainer:
ans += 1
if ans == len(players):
return ans
return ans
# code by PROGIEZ
Additional Resources
- Explore all LeetCode problem solutions at Progiez here
- Explore all problems on LeetCode website here
Happy Coding! Keep following PROGIEZ for more updates and solutions.