Cheapest Fiber Plan Connecting Every Azure Datacenter in a Region

Last updated: November 29, 2026

Quick Overview

Given n datacenters and a list of candidate fiber links with build costs, choose links so that every datacenter is connected and the total cost is minimal. Return the minimum cost, or -1 if a full connection is impossible.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Given n datacenters and a list of candidate fiber links with build costs, choose links so that every datacenter is connected and the total cost is minimal. Return the minimum cost, or -1 if a full connection is impossible.

A minimum spanning tree problem in the style of Microsoft onsites, framed around Azure region network planning. The interviewer checks that you pick Kruskal or Prim, use union find for Kruskal's cycle check, and can argue the cut property behind its correctness.

What the Interviewer Expects
  • Identify the problem as minimum spanning tree
  • Sort candidate links by cost
  • Add a link only if it joins two different components
  • Stop after n - 1 accepted links
  • Return -1 when the graph is disconnected
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
  • When would you prefer Prim's algorithm with a heap?
  • How would you require at least two disjoint paths between datacenters for redundancy?
  • What if some links are mandatory because they already exist?
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: integer n (datacenters 0..n-1) and list of (cost, u, v) candidate links. Output: total cost of the cheapest set of links connecting all datacenters, or -1. Costs are non-negative....

High-Level Design

Kruskal's algorithm: sort links by cost and scan them in that order. For each link, if its endpoints are in different components (checked with union find), accept it and merge the components; otherwis...


Submit Your Answer
Markdown supported