Min Cost to Connect All Points
Given n points on a 2D plane, the cost to connect two points is their Manhattan distance |xi-xj| + |yi-yj|. Return the minimum total cost to connect all points so that there is exactly one simple path between any two points.
Open official problem prompt ↗Wire together all points into one connected tree using the least total Manhattan wiring length.
Laying cable between houses where cost is city-block distance: start at one house and keep extending to whichever unconnected house is nearest to the growing network.
- Input
- points = [[0,0],[2,2],[3,10],[5,2],[7,0]]
- Output
- 20
- Why
- The cheapest tree links (0,0)-(2,2)=4, (2,2)-(3,10)=9, (2,2)-(5,2)=3, (5,2)-(7,0)=4, summing to 20.
1 <= points.length <= 1000-10^6 <= xi, yi <= 10^6All pairs (xi, yi) are distinct