Problem Statement
Statisticians sometimes tell each other the following joke: "An average person has more than an average number of arms."
The joke actually makes sense. As the number of people with more than two arms is quite negligible and some people with fewer than two arms do surely exists, we can be quite certain that the average number of arms is some number that is slightly smaller than 2. On the other hand, an "average person" (interpreted figuratively as "a common, ordinary person") obviously has two arms.
This joke teaches us an interesting thing: sometimes, in a data set there is no average element.
You are given the int[] people: the values of some property for members of a group of people. Determine whether there is someone who is exactly average. Return "present" if there is at least one truly average person in the group, or "absent" if there is no such person.
Definition
- Class:
- AveragePerson
- Method:
- hasAverage
- Parameters:
- int[]
- Returns:
- String
- Method signature:
- String hasAverage(int[] people)
- (be sure your method is public)
Constraints
- people will contain between 1 and 1000 elements, inclusive.
- Each element of people will be between 0 and 1000, inclusive.
Examples
{1, 1, 0, 2, 2, 2, 2, 2, 1, 3, 2, 2, 2, 2, 2, 2, 2}Returns: "absent"
These numbers can represent the number of arms each person has. Even though we have a three-armed person in our group, the average number of arms is somewhere between 1 and 2, and therefore we do not have anyone with an exactly average number of arms.{47}Returns: "present"
There is a single 47-years-old person. The average age in this group is exactly 47 years, and thus the person is exactly average.{184, 180, 178, 177, 165, 190, 186}Returns: "present"
These can be the heights of some people in centimeters. The average height of this group is exactly 180, and we do have a person who is exactly 180 cm tall.{184, 181, 177, 177, 165, 190, 186}Returns: "absent"
The average is the same but this time there is nobody who would be exactly 180 cm tall.