Problem Statement
There is a group of N >= 2 people. All people in the group have different ages, except for one pair of twins who share the same age.
You were shown a photograph. There are N-1 people in the photograph because the N-th person was taking it. For each person in the photograph you were told their age. These are given to you in the int[] ages.
Determine and return the age of the twins. If the age is impossible to determine, return -1 instead.
Definition
- Class:
- WarmupWithTwins
- Method:
- determineTwinsAge
- Parameters:
- int[]
- Returns:
- int
- Method signature:
- int determineTwinsAge(int[] ages)
- (be sure your method is public)
Constraints
- ages will contain between 1 and 50 elements, inclusive.
- Each element of ages will be between 1 and 200, inclusive.
- There will be at most one pair of equal values in ages.
Examples
{10, 47, 20, 30, 47, 40}Returns: 47
There are seven people: the one taking the photograph and the six whose ages you are given. From those ages it is clear that the twins are 47 years old (and that the person taking the photograph is not one of the twins).{10, 20, 30, 50, 40}Returns: -1
One of the twins is taking the picture. We have no idea how old they are. More precisely, we have five options and we do not know which one is correct.{23}Returns: 23
Oh wait, there is a special case? :)