Problem
You get a list points of points on a 2D plane. Each item [x, y] is the position of one point.
The cost to connect two points is the Manhattan distance between them. The Manhattan distance between [x1, y1] and [x2, y2] is |x1 - x2| + |y1 - y2|.
Return the smallest total cost to connect all the points. All the points are connected when a path of connections joins each pair of points.
Example 1
- Input:
- points = [[0,0],[3,0],[3,4],[0,5]]
- Output:
- 11
- Explanation:
- Connect
[0, 0]to[3, 0]for 3,[3, 0]to[3, 4]for 4, and[3, 4]to[0, 5]for 4. The total is 11.
Example 2
- Input:
- points = [[5,-3]]
- Output:
- 0
- Explanation:
- A single point needs no connection.
Constraints
- 1 <= points.length <= 1000
- -10^6 <= x, y <= 10^6
- All the points are different
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 1584. Min Cost to Connect All Points
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source