TopcoderArchiveVisit Topcoder
SRM1 Nov 2010
SRM 499

ColorfulRabbits

Problem statement, definition, constraints, and public examples.

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, 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.
  2. { 0 }
    
    Returns: 1
    A poor lonely rabbit.
  3. { 2, 2, 44, 2, 2, 2, 444, 2, 2 }
    
    Returns: 499
Back to all problems