Problem · Array

Count Max Num Teams 🥝

Learn this problem
EasyAmazonFULLTIMEOA
See Amazon hiring insights

Problem statement

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

Function

countMaxNumTeams(skill: int[], teamSize: int, maxDiff: int) → int

Examples

Example 1

skill = [3, 4, 3, 1, 6, 5]teamSize = 3maxDiff = 2return = 2
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

  • 1 ≤ teamSize ≤ n ≤ 105
  • 1 ≤ maxDiff ≤ 109
  • 1 ≤ skill[i] ≤ 109
  • Only one valid answer exists.
  • More Amazon problems

    drafts saved locally
    public int countMaxNumTeams(int[] skill, int teamSize, int maxDiff) {
      // write your code here
    }
    
    skill[3, 4, 3, 1, 6, 5]
    teamSize3
    maxDiff2
    expected2
    checking account