Statistics

Problem Statement for "HotSpot"

Problem Statement

You are given a set of signal points along a number line, in int[] points. For any given point along the number line, the square of the distance between the point and a signal point is called the distance score. The total distance score of a point is the sum of the distance scores for each signal point.

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. { 1, 5 }

    Returns: 3.0

    When there's two points, the best bet is to go right in the middle of the two.

  2. { 5 }

    Returns: 5.0

  3. { 1, 10, 10 }

    Returns: 7.0

  4. { 4, 7 }

    Returns: 5.5

    Note that the HotSpot point isn't necessarily an integer.

  5. { 99, 14, 62, 3 }

    Returns: 44.5

    The points aren't necessarily given in order.

  6. {1, 2, 4 }

    Returns: 2.3333333333333335

  7. {1, 2, 2, 2, 2 }

    Returns: 1.8


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: