Count Max Num Teams 🥝
Updated
Problem statement
Amazon is hosting a team hackathon.
- 1. Each team will have exactly teamSize developers.
- 2. A developer's skill level is denoted by
skill[i]. - 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 levelsint teamSize: the number of developers to make up a teamint 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) → intExamples
Example 1
skill = [3, 4, 3, 1, 6, 5]teamSize = 3maxDiff = 2return = 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
Constraints
-
1 ≤ teamSize ≤ n ≤ 105 -
1 ≤ maxDiff ≤ 109 -
1 ≤ skill[i] ≤ 109 - Only one valid answer exists.
More Amazon interview questions
- Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
- Search in a Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fill One Exact-Length Binary WindowOA · Seen Nov 2026
- Lexicographically Largest IdentifierOA · Seen Nov 2026
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximal SquareONSITE INTERVIEW · Seen Nov 2026
- Minimum Grid InconvenienceOA · Seen Nov 2026
Similar questions at other companies
- Minimum Parking Roof LengthAmerican Express · OAAmerican Express interview questions
- Sliding Window MedianAuxoAI · OA
- Count Servers With No Requests in a Time WindowIBM · OAIBM interview questions
- Maximum Requests in WindowSalesforce · OASalesforce interview questions
- Earliest Hour with Frequent Badge AccessIntuit · OAIntuit interview questions
- Choose One from Each Set to Minimize the RangeInMobi · OAInMobi interview questions
- Fairest Chocolate PacketsAdobe · PHONE SCREENAdobe interview questions
- Integer Compression OffsetHeadlands Technologies · PHONE SCREENHeadlands Technologies interview questions
- Sliding Window Average After Trimming Both EndsGoogle · ONSITE INTERVIEWGoogle interview questions
- Detect Security Attacks from Network LogsFireworks AI · PHONE SCREEN