Connection Status:
Competition Arena > HotSpot
Rookie SRM 19 · 2023-03-17 · by erinn · Math, Search
Class Name: HotSpot
Return Type: double
Method Name: bestPoint
Arg Types: (vector<int>)
Problem Statement

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.

Constraints

  • points will contain between 1 and 50 elements.
  • Each element of points will be between 0 and 100, inclusive.
Examples
0)
{ 1, 5 }
Returns: 3.0

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

1)
{ 5 }
Returns: 5.0
2)
{ 1, 10, 10 }
Returns: 7.0
3)
{ 4, 7 }
Returns: 5.5

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

4)
{ 99, 14, 62, 3 }
Returns: 44.5

The points aren't necessarily given in order.

Submissions are judged against all 7 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class HotSpot with a public method double bestPoint(vector<int> points) · 7 test cases · 2 s / 256 MB per case

Submitting as anonymous