Cheapest Fiber Plan Connecting Every Data Center
Last updated: November 29, 2026
Quick Overview
Given n data centers and a list of possible fiber links [a, b, cost], return the minimum total cost of a set of links that connects every data center, or -1 if no such set exists.
Meta
November 29, 20260
0
0 solved
Given n data centers and a list of possible fiber links [a, b, cost], return the minimum total cost of a set of links that connects every data center, or -1 if no such set exists.
A Meta onsite question grounded in backbone network planning between data center regions. The interviewer is looking for Kruskal's algorithm with union find, a correct stopping condition, and the ability to justify the greedy choice with the cut property.
What the Interviewer Expects
- Sort candidate links by cost
- Use union find to skip links that would form a cycle
- Stop once n - 1 links are chosen
- Return -1 when the graph is disconnected
- Explain the cut property behind Kruskal
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you compare Kruskal and Prim for a dense graph?
- How would you require at least two disjoint paths between every pair for redundancy?
- Which links are in every minimum spanning tree, and which in none?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
ndata centers0..n-1andlinks[a, b, cost], undirected. - Output: minimum total cost to connect all, or
-1....
High-Level Design
This is a minimum spanning tree. Kruskal's algorithm: sort links by cost and add each link if it joins two different components. Union find answers "different components?" in near-constant time.
Why ...