You want to lay cables between some points on a flat map. The list points holds the coordinates [x, y] of the points.
The cost of a cable between two points [x1, y1] and [x2, y2] is the Manhattan distance: |x1 - x2| + |y1 - y2|.
Return the smallest total cost that connects all the points, so that there is exactly one path between any two points.
Examples
Example 1:
Input: points = [[0,0],[1,3],[4,0],[4,4]]
Output: 12
Explanation: Join (0,0)-(1,3) for 4, (0,0)-(4,0) for 4, and (4,0)-(4,4) for 4. Total = 12.
Example 2:
Input: points = [[2,2],[5,6]]
Output: 7
Explanation: One cable of cost 3 + 4 = 7.
Example 3:
Input: points = [[1,1]]
Output: 0
Explanation: One point needs no cable.