DiffPush Tier Binary Trees · Hard O(n) · O(n)
A corrupted update is detonated on one server blade of a tree-shaped rack network. Each second the corruption jumps to every directly connected blade — the two children and the parent. Ops needs to know the exact second the whole farm goes dark, so they can schedule the isolation window.
Input: A binary tree as a level-order array (null marks a missing child) and an integer start — the value of the initially infected node. Node values are unique.
Output: Return the number of seconds until every node is infected.
1 <= number of nodes <= 10^5-10^4 <= node value <= 10^4Node values are uniqueInput: {"tree":[1,2,3,4,5,null,6,null,null,7,8,null,9,null,null,null,null,null,10],"start":8}
Output: 7
The fire climbs 8 -> 5 -> 2 -> 1 -> 3 -> 6 -> 9 -> 10: seven hops to the farthest blade.
Input: {"tree":[1,2,3],"start":2}
Output: 2
The parent 1 burns first, then the sibling 3 catches it one second later.