#2910

Minimum Number of Groups to Create a Valid Assignment

medium · 24.8% accepted · 395 likes · top 4%

array · hash table · greedy

Description

You are given a collection of numbered balls and instructed to sort them into boxes for a nearly balanced distribution. There are two rules you must follow:

- Balls with the same box must have the same value. But, if you have more than one ball with the same number, you can put them in different boxes.

- The biggest box can only have one more ball than the smallest box.

​Return the fewest number of boxes to sort these balls following these rules.

Solution