2410. Maximum Matching of Players With Trainers Medium

@problem@discussion
#Array#Two Pointers#Greedy#Sorting



1/**
2 * [2410] Maximum Matching of Players With Trainers
3 *
4 * 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.
5 * 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.
6 * Return the maximum number of matchings between players and trainers that satisfy these conditions.
7 *  
8 * Example 1:
9 * 
10 * Input: players = [4,7,9], trainers = [8,2,5,8]
11 * Output: 2
12 * Explanation:
13 * One of the ways we can form two matchings is as follows:
14 * - players[0] can be matched with trainers[0] since 4 <= 8.
15 * - players[1] can be matched with trainers[3] since 7 <= 8.
16 * It can be proven that 2 is the maximum number of matchings that can be formed.
17 * 
18 * Example 2:
19 * 
20 * Input: players = [1,1,1], trainers = [10]
21 * Output: 1
22 * Explanation:
23 * The trainer can be matched with any of the 3 players.
24 * Each player can only be matched with one trainer, so the maximum answer is 1.
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	1 <= players.length, trainers.length <= 10^5
30 * 	1 <= players[i], trainers[j] <= 10^9
31 * 
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/maximum-matching-of-players-with-trainers/
36// discuss: https://leetcode.com/problems/maximum-matching-of-players-with-trainers/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41    pub fn match_players_and_trainers(players: Vec<i32>, trainers: Vec<i32>) -> i32 {
42        0
43    }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_2410() {
54    }
55}
56


Back
© 2025 bowen.ge All Rights Reserved.