Skip to content

Practice Best Position for a Service Centre

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1515
LeetCode Problem

Best Position for a Service Centre

Problem Statement

Choose any real coordinates (x, y) for a service center to minimize the sum of Euclidean distances to all customer positions. The contribution of customer (xi, yi) is sqrt((x - xi)^2 + (y - yi)^2). Return the minimum possible total distance; answers within 10^-5 are accepted.

Source: Best Position for a Service Centre on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
positions = [[0,1],[1,0],[1,2],[2,1]]
Output
4.00000

# Example 2

Input
positions = [[1,1],[3,3]]
Output
2.82843

Constraints

1 <= positions.length <= 50
positions[i].length == 2
0 <= xi, yi <= 100

Related LeetCode Problems

Practice more problems similar to Best Position for a Service Centre.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.