Find Minimum Groups
Learn this problemProblem statement
A financial services company has requested AWS for a private deployment of its cloud network. Considering the sensitive nature of the company's business, AWS has also advised them to add a specific type of security system.
Overall, there are n servers in the network where the security needs of the i-th server are represented by security[i], where each element represents the grade of security needed for a server.
To ensure the highest possible protection, the AWS security team has recommended the following rule to be followed while designing the security system: all servers in a security group must have the same grade of security needs, and the number of servers in any two security groups should not differ by more than 1.
Given an integer array security, find the minimum number of security levels needed to ensure the protection of the network.
Function
findMinimumGroups(security: int[]) → intComplete the function findMinimumGroups in the editor below.
findMinimumGroups has the following parameter:
int security[n]: an integer array denoting the security grade of the devices
Returns
int: an integer denoting the minimum number of groups required
Examples
Example 1
security = [2, 3, 3, 3, 2, 1]return = 4
Consider n = 6 and security = [2, 3, 3, 3, 2, 1].
Then, the elements can be grouped as follows:
- Group 1:
2devices of vulnerability2. - Group 2:
2devices of vulnerability3. - Group 3:
1device of vulnerability3. - Group 4:
1device of vulnerability1.
It requires 4 groups.
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026