15% off all plans & roadmaps Use code
See plansLeetCode 1584 · Solution & editorial
You are given an array points representing integer coordinates of some points on a 2D-plane, where points[i] = [xi, yi].
Min Cost to Connect All Points is a Graph Traversal Patterns (DFS & BFS) problem, in the Minimum Spanning Tree (Kruskal / Prim / DSU + heap) subpattern. The pattern covers DFS/BFS traversal, topological sort, shortest paths, Union-Find, and MST
Find minimum spanning tree using Kruskal's or Prim's algorithm with Union-Find or heap.
The reference solution runs in O(n^2) time and O(n) space.
Min Cost to Connect All Points has been reported in interviews at Directi.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Min Cost to Connect All Points is a Graph Traversal Patterns (DFS & BFS) problem, in the Minimum Spanning Tree (Kruskal / Prim / DSU + heap) subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.