Connect Cartesian Coordinates
You are given a two-dimensional list of integers points
where each element contains [x, y]
representing a cartesian coordinate. We can make an undirected edge between two points (x0, y0)
and (x1, y1)
, which costs abs(x0 - x1) + abs(y0 - y1)
.
Given that we can connect any number of points, return the minimum cost necessary such that every point is connected by a path.
Constraints
0 ≤ n ≤ 1,000
wheren
is the length ofpoints
https://binarysearch.com/problems/Connect-Cartesian-Coordinates
Examples
Example 1
Input
- points =
[[ 0, 0],
[ 0, 1],
[ 0,-1],
[ 1, 0],
[-1, 0]]
Output
- answer =
4
Explanation
We can create an edge from (0, 0)
to every other point.
Leave a comment