AmazonOA #78
Find Minimum Groups (Security Grade Grouping)
Estimated MediumJudge-ready
Topics (AI-labelled)HashingBits & MathGreedy
Each group may only contain servers of the same security level, and the largest and smallest group sizes may differ by at most 1. Find the minimum number of groups.
Input
The first line contains n (1..100000), and the second line contains n levels (1..1000000).
Output
Output a single integer answer.
Example 1
Input:
5
1 1 1 2 2
Output:
2
Example 2
Input:
3
1 2 3
Output:
3
Example 3
Input:
5
7 7 7 7 7
Output:
1
Example notes
Example 1: two groups of sizes 3 and 2 suffice, so the answer is 2. Example 2: different levels can only form one group each, so the answer is 3. Example 3: servers all at the same level can be placed in one group, so the answer is 1.
Editorial
Loading solution…