Problem Statement
Cat Pochi visited a town of rabbits and asked some of the rabbits the following question:
"How many rabbits in this town other than yourself have the same color as you?".
The rabbits all replied truthfully, and no rabbit was asked the question more than once.
You are given the rabbits' replies in the int[] replies.
Return the minimum possible number of rabbits in this town.
Definition
- Class:
- ColorfulRabbits
- Method:
- getMinimum
- Parameters:
- int[]
- Returns:
- int
- Method signature:
- int getMinimum(int[] replies)
- (be sure your method is public)
Constraints
- replies will contain between 1 and 50 elements, inclusive.
- Each element of replies will be between 0 and 1,000,000, inclusive.
Examples
{ 1, 1, 2, 2 }Returns: 5
If there are 2 rabbits with a color and 3 rabbits with another color, Pochi can get this set of replies.{ 0 }Returns: 1
A poor lonely rabbit.{ 2, 2, 44, 2, 2, 2, 444, 2, 2 }Returns: 499