Skip to content

2410. Maximum Matching of Players With Trainers #1922

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to find the maximum number of matchings between players and trainers such that each player's ability is less than or equal to the trainer's capacity. Each player can match with at most one trainer, and each trainer can match with at most one player.

Approach

  1. Sorting: The first step involves sorting both the players and trainers arrays in ascending order. Sorting helps in efficiently applying a greedy strategy to find the maximum matchings.
  2. Greedy Matching with Two Pointers: Using two pointers, one for each array, we traverse through both arrays. For each player, starting from the smallest, we find the smallest available trainer that can accommodate the player's ability. If such a…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Jul 13, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Jul 13, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants