Problem · Tree
Aggregate Machine Topology
Problem statement
A cluster snapshot contains one report from every machine. For each index i, machineIds[i] is a unique machine ID and parentIds[i] is the parent machine's ID. Exactly one machine has parent -1; it is the root. The remaining parent relationships form one rooted tree.
The problem statement continues
ProExamples
Example 1
machineIds = [30,10,20]parentIds = [10,-1,10]return = [[10,-1,0,3],[20,10,1,1],[30,10,1,1]]Machine 10 is the root. Its children are visited as 20 and then 30. The root subtree contains all three machines.
FastPrep Pro
Reported in 1 OpenAI interview this weekUnlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 1 more worked example, explained
- Guided hints and editorial
- Run your code on real test cases
$9/month
Pro subscription, billed yearly — or $19 month-to-month. Cancel anytime.
Free plan — 2 of 2 free unlocks used this week