Tap here to switch tabs
Problem
Submissions

Problem: Min Cost to Connect All Points

Min Cost to Connect All Points gives integer coordinates and asks for the minimum total Manhattan distance needed to connect every point with exactly one simple path between each pair.

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

Min Cost to Connect All Points gives integer coordinates and asks for the minimum total Manhattan distance needed to connect every point with exactly one simple path between each pair.

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.