Contents
Count Maximum Teams Amazon OA 2023 Solution
Amazon is hosting a team hackathon.
- Each team will have exactly teamSize developers.
- A developer’s skill level is denoted by skill[i].
- 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.
Example
skill = [3, 4, 3, 1, 6, 5]
team5ize = 3
maxDiff = 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 oft.
Function Description
Complete the function countMaximumTeams in the editor below.
countMaximumTeams has the following parameter(s):
- int skill[n]: the developers’ skill levels
- int teamSize: the number of developers to make up a team
- int maxDiff: the threshold value
Returns:
- int: the maximum number of teams that can be formed at one time

SOLUTION
Program: Count Maximum Teams Amazon OA Solution in C++
#include<bits/stdc++.h>
using namespace std;
int main() {
int n; cin>>n; vector<int> a(n);
int team, diff; cin>>team>>diff;
sort(a.begin(),a.end());
int i=0, j=team-1, cnt=0;
while(j<n){
if(a[j]-a[i]<=diff){
cnt++;
i=j+1;
j=j+team;
}
else{
i++;
j++;
}
}
cout<<cnt;
return 0;
}
Program: Count Maximum Teams Amazon OA Solution in Java
static int countMaximumTeams(List<int> skill, int teamSize, int maxDiff)
{
skill.Sort();
int i = 0;
int j = teamSize - 1;
int count = 0;
while (j < skill.Count)
{
if (skill[j] - skill[i] <= maxDiff)
{
count++;
i = j + 1;
j = i + 2;
}
else
{
i++;
j++;
}
}
return count;
}
Program: Count Maximum Teams Amazon OA Solution in Python
def countMaximumTeams(skill, teamSize, maxDiff):
teams = 0
n = len(skill)
if n < teamSize:
return teams
skill.sort()
for i in range(n):
if i + teamSize - 1 < n:
diff = skill[i + teamSize - 1] - skill[i]
if diff <= maxDiff:
teams += 1
return teams
Amazon OA 2023 Questions with Solution
- Shopping Patterns Solution Amazon OA 2023
- Reorder Data in Log Files Solution Amazon OA 2023
- Top K Frequent Words Solution Amazon OA 2023
- Trees Height Solution Amazon OA SDE 2023
- Counting Binary Substrings Amazon OA 2023
- Grid Connections Amazon OA 2023
- Shipment Imbalance Amazon OA 2023
- Max Profit Amazon OA 2023
- Find Lowest Price Amazon OA 2023
- Decode String Frequency Amazon OA 2023
- Simple Cipher Amazon OA 2023
- Valid Discount Coupons Amazon OA 2023 Solution
- Minimum Coin Flips Amazon OA 2023
- Max Average Stock Price Amazon OA 2023 Solution
- Robot Bounded In Circle Amazon OA 2023
- Shopping Options Amazon OA 2023 Solution
- Fill The Truck Maximum Units on a Truck Amazon OA Solution
- Maximize Score After N Operations Number Game Solution Amazon OA 2023
- Slowest Key Amazon OA 2023 Solution
- Five Star Seller Maximum Average Pass Ratio Amazon OA 2023
- Split String Into Unique Primes Amazon OA 2023 Solution
- Storage Optimization Amazon OA 2023 Solution
- Minimum Difficulty of a Job Schedule Amazon OA 2023 Solution
- Autoscale Policy Utilization Check Amazon OA 2023
- Optimal Utilization Solution Amazon OA 2023
- Merge Two Sorted Lists Solution Amazon OA 2023
- Two Sum Unique Pairs Solution Amazon OA 2023
- Amazon Music Pairs Amazon OA 2023 Solution
- Class Grouping Amazon OA 2023 Solution
- Find Max products Amazon OA 2023 Solution
- Get encrypted number Amazon OA 2023 Solution
- Find Total Imbalance Amazon OA 2023 Solution
- Find Total Power Amazon OA 2023 Solution