Min Cost to Connect All Points
Medium
Topics
You are given points where points[i] = [x, y]. The cost to connect two points is their Manhattan distance. Return the minimum cost to connect all points so every pair is reachable. (Input rows are the points.)
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^6 <= xi, yi <= 10^6
Run ⌘' · Submit ⌘⏎