Count Maximum Teams Amazon OA 2023

Count Maximum Teams Amazon OA 2023 Solution

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.

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
Count Maximum Teams Amazon OA
Count Maximum Teams Amazon OA 2023 Solution

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

  1. Shopping Patterns Solution Amazon OA 2023
  2. Reorder Data in Log Files Solution Amazon OA 2023
  3. Top K Frequent Words Solution Amazon OA 2023
  4. Trees Height Solution Amazon OA SDE 2023
  5. Counting Binary Substrings Amazon OA 2023
  6. Grid Connections Amazon OA 2023
  7. Shipment Imbalance Amazon OA 2023
  8. Max Profit Amazon OA 2023
  9. Find Lowest Price Amazon OA 2023
  10. Decode String Frequency Amazon OA 2023
  11. Simple Cipher Amazon OA 2023
  12. Valid Discount Coupons Amazon OA 2023 Solution
  13. Minimum Coin Flips Amazon OA 2023
  14. Max Average Stock Price Amazon OA 2023 Solution
  15. Robot Bounded In Circle Amazon OA 2023
  16. Shopping Options Amazon OA 2023 Solution
  17. Fill The Truck Maximum Units on a Truck Amazon OA Solution
  18. Maximize Score After N Operations Number Game Solution Amazon OA 2023
  19. Slowest Key Amazon OA 2023 Solution
  20. Five Star Seller Maximum Average Pass Ratio Amazon OA 2023
  21. Split String Into Unique Primes Amazon OA 2023 Solution
  22. Storage Optimization Amazon OA 2023 Solution
  23. Minimum Difficulty of a Job Schedule Amazon OA 2023 Solution
  24. Autoscale Policy Utilization Check Amazon OA 2023
  25. Optimal Utilization Solution Amazon OA 2023
  26. Merge Two Sorted Lists Solution Amazon OA 2023
  27. Two Sum Unique Pairs Solution Amazon OA 2023
  28. Amazon Music Pairs Amazon OA 2023 Solution
  29. Class Grouping Amazon OA 2023 Solution
  30. Find Max products Amazon OA 2023 Solution
  31. Get encrypted number Amazon OA 2023 Solution
  32. Find Total Imbalance Amazon OA 2023 Solution
  33. Find Total Power Amazon OA 2023 Solution