FastPrepFastPrep
Problem Brief

Count Max Num Teams πŸ₯

FULLTIMEOA

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

1Example 1

Input
skill = [3, 4, 3, 1, 6, 5], teamSize = 3, maxDiff = 2
Output
2
Explanation
Example 1 illustration
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

Limits and guarantees your solution can rely on.

  • 1 ≀ teamSize ≀ n ≀ 105
  • 1 ≀ maxDiff ≀ 109
  • 1 ≀ skill[i] ≀ 109
  • Only one valid answer exists.
  • public int countMaxNumTeams(int[] skill, int teamSize, int maxDiff) {
      // write your code here
    }
    
    Input

    skill

    [3, 4, 3, 1, 6, 5]

    teamSize

    3

    maxDiff

    2

    Output

    2

    Sign in to submit your solution.