Skip to the editor
JSGroundwork
JSGroundwork handwritten · web dev
←Back to Minimum Spanning Tree

Ready to read

JSJavaScript⑂Git◎Interview prepΣDSA in JSSDSystem Design
More topics15›
</>HTML{ }CSS⚛ReactNNext.jsNeNest.jsTSTypeScriptNoNode.js🐳DockerDBSQL & Databases✓Testing🔒Web Security☁Cloud & DevOps◈GraphQL◆Redis☸Kubernetes
☰‹›
Description
All topics›JavaScript›Minimum Spanning Tree

Min Cost to Connect All Points

advancedlayer A4 · Minimum Spanning Tree5 tests

Given points, an array of [x, y] coordinates on a plane, connect every point so that there is exactly one path between any two of them, at minimum total cost.

  • The cost of a connection is the Manhattan distance |x1 - x2| + |y1 - y2|
  • Return that minimum total cost — this is a minimum spanning tree
  • Fewer than two points cost 0
  • A compact MinHeap keyed on item[0] is already written for you in the starter, so you can concentrate on the MST itself

Stuck?

All exercisesPlayground
1234567891011121314
loading the editor…

Nothing yet — hit Run and whatever you log shows up here.

Submit to see how you did.

⌘/Ctrl + Enter run⌘/Ctrl + S save⌘/Ctrl + / comment⌘/Ctrl + F find/replace⌘/Ctrl + D select next matchAlt + click multi-cursorTab indent · ⇧Tab outdentEsc leave fullscreen