Skip to main content
Back to problems
Leetcode
Medium
Arrays
Sorting
Greedy
Amazon
Maximum Matching Of Players With Trainers

Match as many players as possible with trainers whose capacity is at least the player's requirement.

Acceptance 100%
Problem Statement

You are given two integer arrays: players and trainers.

Each player has a minimum training capacity requirement, and each trainer has a capacity value. A player can be matched with a trainer only if the trainer's capacity is greater than or equal to the player's requirement. Each player and each trainer can be used at most once.

Return the maximum number of matches you can form.

The goal is to pair players and trainers so that the number of valid pairs is as large as possible.

Input Format

  • Two integer arrays players and trainers.
  • players[i] is the requirement of the ii-th player.
  • trainers[j] is the capacity of the jj-th trainer.

Output Format

  • Return a single integer: the maximum number of valid player-trainer matches.

Constraints

  • Each player and trainer may be used at most once.
  • A match is valid only if trainerCapacity >= playerRequirement.
  • Arrays may be unsorted.
Examples
Sample cases returned by the problem API.

Example 1

Input

players = [4, 7, 9]
trainers = [8, 2, 5, 8]

Output

2

Explanation

After sorting, players = [4, 7, 9] and trainers = [2, 5, 8, 8].

  • Match player 4 with trainer 5.
  • Match player 7 with trainer 8. Player 9 cannot be matched. So the maximum number of matches is 2.

Example 2

Input

players = [1, 1, 1]
trainers = [1, 2]

Output

2

Explanation

Two players can be matched: one with trainer 1 and one with trainer 2. One player remains unmatched.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.