medium

Min Cost to Connect All Points

You are given points in the plane. The cost of connecting two points is their Manhattan distance. Return the minimum total cost to connect all points so that every pair is linked by some path.

Constraints
  • 1 ≤ points.length ≤ 1000
  • -10^6 ≤ x, y ≤ 10^6
  • All points distinct
Examples
in: points = [[0,0],[2,2],[3,10],[5,2],[7,0]]
out: 20

Code it yourself

Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?

Choose an approach to check your pattern recognition, or reveal the discussion when you need help.