Algorithm for maximizing the number of same-sized groups
Hint:

 Try working through some examples.  Can you narrow down the set of possible values that might appear in the largest group in the best solution?  (For instance, your second example has 2's as the value, and your third example has 4's or 5's.)  Can you see how to use that to help you do better than brute force?