Min Cost to Connect All Points
Updated
Problem statement
You are given an array points representing integer coordinates of some points on a 2D-plane, where points[i] = [xi, yi].
The cost of connecting two points [xi, yi] and [xj, yj] is the manhattan distance between them: |xi - xj| + |yi - yj|, where |val| denotes the absolute value of val.
Return the minimum cost to make all points connected. All points are connected if there is exactly one simple path between any two points.
Function
minCostConnectPoints(points: int[][]) → intExamples
Example 1
points = [[0,0],[2,2],[3,10],[5,2],[7,0]]return = 20
We can connect the points as shown above to get the minimum cost of 20. Notice that there is a unique path between every pair of points.
Example 2
points = [[3,12],[-2,5],[-4,1]]return = 18The points can be connected in various ways to get the minimum cost of 18.
Constraints
1 <= points.length <= 1000-10^6 <= xi, yi <= 10^6- All pairs
(xi, yi)are distinct.
More Nutanix interview questions
- Print FooBar AlternatelyPHONE SCREEN · Seen Nov 2026
- Design Hit CounterONSITE INTERVIEW · Seen Oct 2026
- Peak Process MemoryONSITE INTERVIEW · Seen Aug 2026
- Good SubsequencesOA · Seen Jul 2026
- Minimum Operations to Transform ArrayONSITE INTERVIEW · Seen Jun 2026
- Count Connected Components in an Undirected GraphONSITE INTERVIEW · Seen Aug 2025
- Digit Changes for a Multiple of 9OA · Seen Aug 2025
- Gas Station Loop StartOA · Seen Aug 2025
- LRU CacheONSITE INTERVIEW · Seen Aug 2025
- Running Median of a Multilevel Linked List in Level OrderONSITE INTERVIEW · Seen Aug 2025
Similar questions at other companies
- Minimum Operations to Sort with Rotations Then SwapsBank of New York Mellon · OA
- Maximum Sum of a K-StarMicrosoft · OAMicrosoft interview questions
- Optimal TransferSnowflake · OASnowflake interview questions
- Maximum K-Star SumC3.ai · OAC3.ai interview questions
- Maximum K-Star SumAkuna Capital · OAAkuna Capital interview questions
- Doctor Appointment Slot AssignmentDRW · OADRW interview questions
- Google Drive Folder Hierarchy SyncGoogle · OAGoogle interview questions
- Maximize Throughput (AMS)TikTok · OATikTok interview questions
- Minimum Cost to Supply Water with Wells and PipesInfosys · OAInfosys interview questions
- Optimal TransferVisa · OAVisa interview questions
Nutanix interview experiences
- Nutanix interviews · November 2026
- Nutanix SWE Intern Phone Screens: 20 Experiences (Part 3 of 3)
- Nutanix SWE Intern OA Questions: 16 Experiences (Part 2 of 3)
- Nutanix U.S. SWE Intern Interviews: 54 Experiences (Part 1 of 3)
- Nutanix SWE OA and Interviews, Level Not Reported: 9 Experiences
- Nutanix Intern Debugging Round and Interviews: 25 Experiences