Description
Solutions
Count Max Num Teams πŸ₯
πŸ”₯ FULLTIME

Amazon is hosting a team hackathon.

  1. 1. Each team will have exactly teamSize developers.
  2. 2. A developer's skill level is denoted by skill[i].
  3. 3. The difference between the maximum and minimum skill levels within a team cannot exceed a threshold, maxDiff.

Determine the maximum number of teams that can be formed from the contestants.

Complete the function countMaxNumTeams which has the following parameters

  • int skill[n]: the developers' skill levels
  • int teamSize: the number of developers to make up a team
  • int maxDiff: the threshold value.

int: the maximum number of teams that can be formed at one time

Example 1:

Input:  skill = [3, 4, 3, 1, 6, 5], teamSize = 3, maxDiff = 2
Output: 2
Explanation:
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 πŸ¦‹ Credit to Λšκ’°αƒ mehh ΰ»’κ’±Λš πŸ¦‹
Constraints:
  • 1 ≀ teamSize ≀ n ≀ 105
  • 1 ≀ maxDiff ≀ 109
  • 1 ≀ skill[i] ≀ 109
  • Only one valid answer exists.
Thumbnail 0
Thumbnail 1
Testcase

Result
Case 1

input:

output: