Cheapest Fiber Links to Connect All Regional Data Centers

Last updated: November 29, 2026

Quick Overview

Given n data center regions and candidate fiber links (a, b, monthly_cost), return the minimum total cost of links that connects every region, or -1 if the candidates cannot connect them all.

Uber
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given n data center regions and candidate fiber links (a, b, monthly_cost), return the minimum total cost of links that connects every region, or -1 if the candidates cannot connect them all.

Uber operates across multiple data center regions and cloud zones, and infrastructure teams weigh connectivity costs. The technical screen checks Kruskal's algorithm with union find and an explanation of why the greedy cut property gives an optimal spanning tree.

What the Interviewer Expects
  • Identify the problem as a minimum spanning tree
  • Sort edges by cost and add those that join different components
  • Use union find to detect cycles in near constant time
  • Stop after n - 1 edges and detect disconnection
  • Explain the cut property briefly
Key Topics to Cover
minimum spanning tree
Kruskal's algorithm
union find
greedy
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if some links are mandatory for compliance and must be included?
  • How would you add redundancy so any single link failure keeps everything connected?
  • When would Prim's algorithm be a better choice?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: n regions 0..n-1, links list of (a, b, cost) with non-negative costs.
  • Output: minimum total cost of a connected spanning subgraph, which is always a tree at optimum; -1 if impossibl...
High-Level Design

Kruskal: sort links by cost, then scan. A link joining two different components is safe to add by the cut property, since it is the cheapest edge crossing the cut between its component and the rest. U...


Submit Your Answer
Markdown supported