Min Cost to Connect All Points
A medium-tier problem at 69% community acceptance, tagged with Array, Union Find, Graph. Reported in interviews at Directi and 4 others.
Min Cost to Connect All Points is a Minimum Spanning Tree problem dressed up as a geometry puzzle. You're given points on a 2D plane and need to find the cheapest way to connect them all, where cost is the Manhattan distance between pairs. It shows up at Directi, Nutanix, DE Shaw, TikTok, and Uber. The acceptance rate sits at 69%, which sounds high until you realize most candidates build the graph correctly but then either botch the MST algorithm or time out on the distance calculation. This is the kind of problem where a single forgotten optimization tanks your solution in the live assessment.
Companies that ask "Min Cost to Connect All Points"
Min Cost to Connect All Points is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.
Get StealthCoderThe trap is thinking you need to precompute all pairwise distances upfront. You don't. The trick is building an edge list of Manhattan distances between every pair of points, sorting by cost, then running Kruskal's algorithm with Union Find to pull out the minimum spanning tree. The Union Find implementation is where most candidates leak time or make mistakes, especially around path compression and rank optimization. Array handling is straightforward. Graph theory here just means you're modeling the problem as a complete weighted graph. If you hit this problem cold during an assessment and your first instinct is to sort naively or forget to track visited edges, StealthCoder will surface the optimized approach in seconds, invisible during screen share.
Pattern tags
You know the problem.
Make sure you actually pass it.
Min Cost to Connect All Points recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Min Cost to Connect All Points interview FAQ
How do I know which MST algorithm to use, Kruskal or Prim?+
Kruskal's is simpler to code under pressure because you sort edges globally and use Union Find. Prim's requires tracking visited nodes and recalculating min edges per step. For a complete graph (every point connects to every other), either works, but Kruskal plus Union Find is the safer bet in a timed OA.
What's the actual trick if I've seen Minimum Spanning Tree problems before?+
The trick isn't the MST algorithm, it's that you must generate all pairwise distances and sort them. Candidates often try to build the MST incrementally without presorting, which wastes time. Sort first, then apply Kruskal's with a good Union Find implementation using path compression and union by rank.
Will this problem definitely come up in my Uber or TikTok interview?+
No, but it's in their historical ask list. Companies cycle through problem types, so it's probable but not certain. The fact that Directi, Nutanix, DE Shaw, TikTok, and Uber have all asked it means the pattern is tested. Treat it as a must-know for those company pipelines.
Is Union Find the bottleneck or the distance calculation?+
Distance calculation is O(n squared) and unavoidable since you must generate all edges. Union Find with path compression and rank is nearly O(1) amortized per operation, so it's not the bottleneck. The bottleneck is sorting the edge list, which is O(n squared log n). Make sure your Union Find implementation is tight to avoid compounding the overhead.
How much harder is this than a standard Minimum Spanning Tree problem?+
Not much harder algorithmically, but the 2D geometry context and Manhattan distance calculation trip up candidates who've only done MST on pre-built graphs. The real difficulty is executing cleanly under time pressure without off-by-one errors in the distance loop or Union Find edge cases.
Want the actual problem statement? View "Min Cost to Connect All Points" on LeetCode →