Connect all supplied points using edges costing Manhattan distance, abs(dx)+abs(dy). Return the minimum total cost of a connected network.
Example 1
Input points in coordinate order. All candidate connections are shown, weighted by Manhattan distance; choose a minimum spanning tree.points = [[0,0],[2,0],[2,3]]
5
Explanation
Connect [0,0] to [2,0] for 2 and [2,0] to [2,3] for 3, totaling 5.
Example 2
Input points in coordinate order. All candidate connections are shown, weighted by Manhattan distance; choose a minimum spanning tree.Explanation
One point already forms a connected network with no edge cost.
Example 3
Input points in coordinate order. All candidate connections are shown, weighted by Manhattan distance; choose a minimum spanning tree.points = [[-1,0],[1,0],[0,2]]
5
Explanation
Connect the horizontal points for 2 and attach [0,2] for 3, totaling 5.
Constraints
- 1 <= number of distinct points <= 1000
- Coordinates are -1000000..1000000
Function contractminCostConnectPointsArguments: json