Lowest Cost Leased Lines to Connect Every Regional Data Center

Last updated: November 29, 2026

Quick Overview

Given n regional data centers and quotes `(cost, a, b)` for leasing a private line between two of them, choose lines so every data center can reach every other at minimum total cost. Return the cost and lines chosen, or None if no full connection is possible.

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

0

0

0 solved


Given n regional data centers and quotes `(cost, a, b)` for leasing a private line between two of them, choose lines so every data center can reach every other at minimum total cost. Return the cost and lines chosen, or None if no full connection is possible.

TikTok runs data centers across many regions with data residency programs such as Project Texas, so backbone planning is a natural setting for a minimum spanning tree question. The interviewer checks Kruskal with union-find, why the cut property makes the greedy optimal, and detection of a disconnected input.

What the Interviewer Expects
  • Recognizes a minimum spanning tree problem
  • Kruskal with sorted edges and union-find
  • Union by size and path compression or halving
  • Detects when fewer than n - 1 edges can be chosen
  • Explains the cut property in a sentence or two
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
  • Some regions must not be directly linked for data residency reasons; how do you handle forbidden edges?
  • You need the network to survive any single line failure; what problem is that?
  • How would Prim's algorithm compare on a dense quote matrix?
  • A new quote arrives after the tree is built; how do you update it cheaply?
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

Undirected weighted edges, possibly parallel, n nodes. Output minimum total cost of a connecting set of edges (a spanning tree) and the edges, or None when the graph is disconnected. n = 1 needs no li...

High-Level Design

Kruskal: sort quotes by cost and add each one that connects two different components, tracked with union-find. Stop once n - 1 lines are chosen. Correctness follows from the cut property: for any spli...


Submit Your Answer
Markdown supported