Amazon Online Assessment 2021 (OA) - Count Maximum Teams

In this coding challenge, we have a bunch of coders taking part in a competition; each coder has a certain skill level represented as skill[i]. To make the contest fair, the organizers have decided to create teams of a specific size, called teamSize; each team will comprise this exact number of coders. However, they also need to make sure that the variation in skills within each team isn't too big, so they have set a rule: the gap between the highest skill and the lowest skill in a team can't go beyond a certain limit which is maxDiff. Now, the question here is to figure out what's the greatest number of teams we can form from all the coders while respecting these rules.

Example

  • skill = [3, 4, 3, 1, 6, 5], teamSize = 3, maxDiff = 2: At most, 2 teams can be formed: [3, 3, 1] and [4, 6, 5]. The difference between the maximum and minimum skill levels is 2 in each case, which does not exceed the threshold value of 2.

Solution and Explanations

โ†
โ†‘TA ๐Ÿ‘จโ€๐Ÿซ