Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Min Cost to Connect All Points

Medium

Topics
GraphMinimum Spanning TreeHeap

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 ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access