Min Cost to Connect All Points
You are given an array points representing integer coordinates of some points on a 2D-plane, where points[i] = [xi, yi]. The cost of connecting two points [xi, yi] and [xj, yj] is the manhattan distance between them: |xi - xj| + |yi - yj|. Return the minimum cost to make all points connected.

30:00

Min Cost to Connect All Points
medium
Topics
Companies

You are given an array points representing integer coordinates of some points on a 2D-plane, where points[i] = [xi, yi]. The cost of connecting two points [xi, yi] and [xj, yj] is the manhattan distance between them: |xi - xj| + |yi - yj|. Return the minimum cost to make all points connected.

Example 1:
Input: [[0,0],[2,2],[3,10],[5,2],[7,0]]
Output: 20
Constraints:
  • 1points.length10001 \leq \text{points.length} \leq 1000

  • 106xi,yi106-10^6 \leq x_i, y_i \leq 10^6

  • All pairs (xi,yi)(x_i, y_i) are distinct.

Input
arr =[[0,0],[2,2],[3,10],[5,2],[7,0]]

Start Prim's Cost: 0

0

1

2

3

4

Variables
No variables to display
DepthFunction Call
Stack empty
0/24