diff options
author | Jack Sangdahl <[email protected]> | 2025-07-12 18:21:33 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-07-12 18:21:33 -0600 |
commit | e608af56c0aba66323fb253f4bd2dfe3d2b38fb8 (patch) | |
tree | 060a8e3d972247e3623df4dfe697852c819d1b68 /max_match_players_trainers.py | |
parent | 8930229b57da95f3030a01302d7ba318353f980d (diff) | |
download | leetcode-e608af56c0aba66323fb253f4bd2dfe3d2b38fb8.tar.gz leetcode-e608af56c0aba66323fb253f4bd2dfe3d2b38fb8.zip |
2410. maximum matching of players with trainers
Diffstat (limited to 'max_match_players_trainers.py')
-rw-r--r-- | max_match_players_trainers.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/max_match_players_trainers.py b/max_match_players_trainers.py new file mode 100644 index 0000000..63463ff --- /dev/null +++ b/max_match_players_trainers.py @@ -0,0 +1,35 @@ +# 2410. Maximum Matching of Players With Trainers +import heapq + +""" +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 j'th capacity +of the trainer. the i'th player can match with the j'th trainer if the +players ability is less than or equal to the trainers training capacity. +additionally, the i'th player can matchedwith at most one trainer, and the +j'th trainer can be matched with at most one player. return the maximum +number of matchings between 'players' and 'trainers' that satisfy these +conditions. +""" + + +class Solution(object): + def matchPlayersAndTrainers(self, players, trainers): + """ + :type players: List[int] + :type trainers: List[int] + :rtype: int + """ + heapq.heapify(players) + trainers.sort() + return sum( + bool(players and players[0] <= i and heapq.heappop(players)) + for i in trainers + ) + + +if __name__ == "__main__": + obj = Solution() + print(obj.matchPlayersAndTrainers(players=[4, 7, 9], trainers=[8, 2, 5, 8])) + print(obj.matchPlayersAndTrainers(players=[1, 1, 1], trainers=[10])) |