AMAZON | OA | SDE1 | 2022
Anonymous User
1995

QUESTION: Bob is the coach of a cricket team and he has N players each having a training capacity of Ai. He also has M trainers with training capacity Bi which can train players for their better performance. Any trainer can train only one player and one player can take training from only one trainer.

Bob wants the maximum number of players from his team to get training from trainers. But the players can only take training from the trainer if the trainer's training capacity Bj(1<=j<=M) is less than or equal to the training capacity of that player Ai.

Determine the maximum number of players who can take training if trainers are assigned optimally.

NOTES:

  • There can be multiple players or trainers with same training capacities.
  • you have to output only the count of players who can get training from trainers.

EXAMPLE 1:
If N=3 and M=3,
A=[20, 10, 30] and B=[40, 5, 10]

  • For Player 1: A1=20 can get training from trainer 2 having a training capacity of 5.
  • For Player 2: A2=10 can get training from trainer 3 having a training capacity of 10.
  • For Player 3: A3=30 cannot get any trainer as only one trainer is left with the capacity of 40.
  • Hence, the answer is 2.

EXAMPLE 2:
If N=4 and M=3,
A=[20, 10, 20, 40] and B=[40, 5, 30]

  • Player 2 having a training capacity of 10 can take training from trainer 2 who has training capacity of 5.
  • Player 4 having a training capacity of 40 can take training from trainer 1 having a training capacity of 40 or trainer 3 having a training capacity of 30.
  • Hence, the maximum output is 2.
Comments (8)