Problem Statement
You are given a set of signal points along a number line, in
We call the point along the number line with the lowest total distance score the hotspot. Given a set of signal points, return the location of the hotspot.
Definition
- Class:
- HotSpot
- Method:
- bestPoint
- Parameters:
- int[]
- Returns:
- double
- Method signature:
- double bestPoint(int[] points)
- (be sure your method is public)
Constraints
- points will contain between 1 and 50 elements.
- Each element of points will be between 0 and 100, inclusive.
Examples
{ 1, 5 }
Returns: 3.0
When there's two points, the best bet is to go right in the middle of the two.
{ 5 }
Returns: 5.0
{ 1, 10, 10 }
Returns: 7.0
{ 4, 7 }
Returns: 5.5
Note that the HotSpot point isn't necessarily an integer.
{ 99, 14, 62, 3 }
Returns: 44.5
The points aren't necessarily given in order.
{1, 2, 4 }
Returns: 2.3333333333333335
{1, 2, 2, 2, 2 }
Returns: 1.8