The Maximum Matching of Players With Trainers coding problem gives you two arrays: player abilities and trainer capacities. A player can be matched with a trainer if the player's ability is less than or equal to the trainer's capacity. Each player and trainer can be in at most one match. Maximize the number of matched pairs.
Meta, Amazon, and Google include this problem because it is a clean application of greedy two-pointer technique after sorting. It directly mirrors the classic "assign tasks to workers with capacity constraints" pattern. Candidates who recognize this as a bipartite matching problem solvable greedily (without complex matching algorithms) because of the sorted order demonstrate strong pattern recognition.
Greedy with two pointers after sorting: Sort both arrays. Use two pointers p (players) and t (trainers). If players[p] <= trainers[t], match them: increment both pointers and count. Otherwise, move the trainer pointer forward (current trainer is too weak for this player, but a stronger trainer might work). This greedy works because sorted order ensures we always try the weakest available trainer that can handle the current (weakest unmatched) player.
Time: O(n log n + m log m) for sorting, O(n + m) for the two-pointer scan.
Players: [4, 7, 9], Trainers: [8, 2, 5, 10]
For the Array Sorting Two Pointers Greedy interview pattern, remember this rule: "sort both arrays, match the weakest valid pair first." This pattern — two sorted arrays, one-to-one matching with a capacity constraint — appears frequently in scheduling, resource allocation, and pairing interview problems. It always yields an O(n log n) greedy solution.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Minimize Maximum Pair Sum in Array | Medium | Solve | |
| Maximum Calories Burnt from Jumps | Medium | Solve | |
| Bag of Tokens | Medium | Solve | |
| Advantage Shuffle | Medium | Solve | |
| Boats to Save People | Medium | Solve |