← Questions
Group GPUs by node, then partition them by links
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Microsoft's technical phone screen, last asked Jan 2026. It tests graphs, union-find and grouping.
You are given a list of GPUs, each on a machine (node), and a list of high-speed links between pairs of GPUs. First group the GPUs by node. Then, within each node, split its GPUs into sets that are connected to each other through links inside that node.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
group_by_node(gpus: list[tuple[str, str]]) -> dict[str, list[str]]—gpusholds(gpu_id, node_id); returns each node's GPU ids, sorted. -
partition_by_links(gpus: list[tuple[str, str]], links: list[tuple[str, str]]) -> dict[str, list[list[str]]]— for each node, its GPUs split into connected sets using only links between GPUs on that node. Each set is sorted; sets are ordered by their smallest id. A GPU with no links is a set of one.
Example
gpus = [("g0", "n0"), ("g1", "n0"), ("g2", "n0"), ("g3", "n0"), ("g4", "n1"), ("g5", "n1")]
links = [("g0", "g1"), ("g2", "g3"), ("g1", "g4"), ("g4", "g5")]
group_by_node(gpus) -> {"n0": ["g0", "g1", "g2", "g3"], "n1": ["g4", "g5"]}
partition_by_links(gpus, links) -> {"n0": [["g0", "g1"], ["g2", "g3"]], "n1": [["g4", "g5"]]}
# g1-g4 joins two different nodes, so it is ignored
Constraints
- Up to 10^5 GPUs and 10^6 links.
- Links are undirected; duplicates and links to unknown GPUs may appear.
Clarifying questions
- Do links between GPUs on different nodes matter for the partition?
- Should sets be connected components, or groups of a fixed size (for example pairs for tensor parallelism)?
- How should the output be ordered?
- What should happen with links that name unknown GPUs?
What a strong answer covers
- A hash map from node to GPUs for the grouping.
- Connected components within each node with union-find (or BFS), skipping cross-node and unknown links.
- O((G + L) * alpha(G)) time with union-find, O(G) space.
- Deterministic ordering of the output.
- Tests: isolated GPUs, a node with one GPU, duplicate links, cross-node links.
Follow-ups
- Split each node's GPUs into groups of exactly
gthat keep as many links as possible inside groups. Why is this hard in general, and what heuristic would you use? - Links have bandwidths: prefer groups connected by the fastest links.
- GPUs and links arrive and fail over time: keep the partition up to date.
Where it's asked
- Microsoft · Technical phone screen · Last asked Jan 202660 min · One technical round
What it tests
graphs · union-find · grouping
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
