Minimum cost to connect all points
Mediumgraphminimum spanning treeprim
Connecting points [x1, y1] and [x2, y2] costs |x1 - x2| + |y1 - y2|. Return the minimum total cost to connect every point so there's a path between any two.
Example 1
Input: points = [[0,0],[2,2],[3,10],[5,2],[7,0]] Output: 20
Example 2
Input: points = [[3,12],[-2,5],[-4,1]] Output: 18
Constraints
- 1 ≤ points.length ≤ 1000
- -10⁶ ≤ x, y ≤ 10⁶
- All points are distinct
Submit checks your solution against 7 tests, including hidden ones.
/**
* @param {int[][]} points
* @return {int}
*/
function minCostConnectPoints(points) {
}