Problem Statement
There is a group of N >= 2 people. There are some individuals and some pairs of twins. If we write down the age of each individual and also the age of each pair of twins (but only once, not twice), the numbers we will get are all distinct integers between 1 and 200, inclusive.
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.
Given what you know, determine the following values:
- Amax = the largest possible age of a pair of twins
- Tmax = the largest possible number of pairs of twins
Return the int[] {Amax, Tmax}. That is, return a int[] in which element 0 is Amax and element 1 is Tmax.
Definition
- Class:
- RealTaskWithTwins
- Method:
- solve
- Parameters:
- int[]
- Returns:
- int[]
- Method signature:
- int[] solve(int[] ages)
- (be sure your method is public)
Notes
- It can be shown that Tmax is always positive and therefore Amax is always defined.
Constraints
- ages will contain between 1 and 50 elements, inclusive.
- Each element of ages will be between 1 and 200, inclusive.
- Each value will occur at most twice in ages.
Examples
{10, 20, 30, 10, 30}Returns: {30, 3 }It is possible that there are three pairs of twins. This happens precisely when the person taking the photograph is 20 years old, and thus the twin of one of the people in the photograph. Regardless of the age of the missing person, the oldest pair of twins are the two 30-year-olds in the photograph.{47}Returns: {47, 1 }The person taking the photograph may or may not be the twin of the person in it.{10, 50, 47, 20, 24, 43, 13}Returns: {50, 1 }