Tap here to switch tabs
Problem
Submissions

Problem: Min Cost to Connect All Points

Try to solve the Min Cost to Connect All Points problem.

Statement

You are given an array points representing integer coordinates of some points on a 2D2 {D} plane, where points[i] =[xi,yi]= [x_i, y_i].

The cost of connecting two points [xi,yi][x_i, y_i] and [xj,yj][x_j, y_j] is the Manhattan distance between them: ∣xi−xj∣+∣yi−yj∣|x_i - x_j| + |y_i - y_j|.

Return the minimum total cost to connect all points such that there is exactly one simple path between any pair of points.

Constraints:

  • 1≤1 \leq points.length ≤1000\leq 1000

  • −106≤xi,yi≤106-10^6 \leq x_i, y_i \leq 10^6

  • All pairs (xi,yi)(x_i, y_i) are distinct.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Min Cost to Connect All Points

Try to solve the Min Cost to Connect All Points problem.

Statement

You are given an array points representing integer coordinates of some points on a 2D2 {D} plane, where points[i] =[xi,yi]= [x_i, y_i].

The cost of connecting two points [xi,yi][x_i, y_i] and [xj,yj][x_j, y_j] is the Manhattan distance between them: ∣xi−xj∣+∣yi−yj∣|x_i - x_j| + |y_i - y_j|.

Return the minimum total cost to connect all points such that there is exactly one simple path between any pair of points.

Constraints:

  • 1≤1 \leq points.length ≤1000\leq 1000

  • −106≤xi,yi≤106-10^6 \leq x_i, y_i \leq 10^6

  • All pairs (xi,yi)(x_i, y_i) are distinct.