Find Minimum Groups
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The data structure this Amazon problem hinges on is a frequency map, and that's what the June 2026 reports keep pointing to. You get an array of security grades. You split it into groups where every group holds one grade, and no two groups differ in size by more than 1. Minimize the group count. It reads like a grouping puzzle, but it's counting plus a size search. If you blank when the OA clock is running, StealthCoder sits invisibly on your screen as a safety net. Here's the actual trick so you may not need it.
The problem
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[]) → int Complete 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: 2 devices of vulnerability 2. Group 2: 2 devices of vulnerability 3. Group 3: 1 device of vulnerability 3. Group 4: 1 device of vulnerability 1. It requires 4 groups.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Count how often each grade appears with a hash map. Now you only care about the counts. Pick a group size k, and every count c must split into groups of size k or k+1. That works when c divided into ceil(c/(k+1)) groups still has each group at least k, meaning ceil(c/(k+1)) * k <= c. Try k from the smallest count down to 1, and the first valid k gives the answer: sum of ceil(c/(k+1)) across all counts. The pitfall is guessing sizes from the global minimum count only or using greedy splitting per grade. Group sizes must be consistent across all grades. Check example 1: counts are 2, 3, 1. With k=1, sizes 1 or 2 work, giving 1 + 2 + 1 = 4. If the search logic slips live, StealthCoder is the hedge on the OA.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Find Minimum Groups cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Find Minimum Groups FAQ
What's the trick in Find Minimum Groups?+
Count each grade's frequency with a hash map, then forget the grades. You're splitting counts into groups of size k or k+1. Try k from the smallest frequency down to 1 and take the first k that every count can satisfy. Sum ceil(c/(k+1)) for the answer.
How do I check if a group size k works for a count?+
For a count c, use g = ceil(c/(k+1)) groups, the fewest groups with max size k+1. Then check g * k <= c. If it holds, c splits into g groups with sizes between k and k+1. If it fails for any count, k is invalid.
How hard is this Amazon OA question really?+
Medium. The hash map part is easy. The hard part is seeing that group size must be shared across all grades, then deriving the validity check. Once you see that, the code is about 15 lines. Test it on the sample first.
What's the time complexity?+
Building the frequency map is O(n). Then you try up to min-count values of k, each costing O(d) where d is the number of distinct grades. That's fine for typical constraints since min count times d is at most n. You can also binary search, but it's not required.
How do I prep for this in 48 hours?+
Write the frequency map and the k-search from scratch twice. Test edge cases: all grades identical, all unique (answer equals n), and counts like 5 and 2 where the best k is 2 or 1. Practice explaining why ceil(c/(k+1)) minimizes groups.