Fundamentals/Count Maximum Teams
← PrevNext →
Given an array skill where skill[i] is the skill level of the i-th coder, an integer teamSize, and an integer maxDiff, form as many teams as possible. Each team must have exactly teamSize coders, and the difference between the highest and lowest skill in any team must not exceed maxDiff. Each coder belongs to at most one team. Return the maximum number of teams.
Input
skill: array of integer skill levels
teamSize: required team size
maxDiff: maximum allowed skill spread within a team
Output
The maximum number of teams that can be formed.
Examples
Example 1
Inputskill = [3, 4, 3, 1, 6, 5], teamSize = 3, maxDiff = 2
Output2
Example 2
Inputskill = [1, 1, 3, 4, 5, 9], teamSize = 1, maxDiff = 1
Output6
Constraints
1 <= skill.length <= 10^5.
1 <= teamSize <= skill.length.
0 <= maxDiff.