The spread-to-parent part is what gets you.
Model the tree as an undirected graph and perform a multi-source BFS from the target node, treating each edge as unit weight. The answer is the maximum distance from the target to any node, which can be computed in O(n) time. Alternatively, use a two-pass DFS to compute the farthest distance in each subtree and combine with the distance from the target.
Pro tip: Clarify that the tree is unrooted for the fire spread, so parent edges must be considered. Mention that the solution is O(n) time and O(n) space, and that it can be optimized to O(1) extra space with a DFS that returns the farthest distance in the subtree.
Confirm that the tree is binary, the target node is given, and fire spreads to all adjacent nodes (left, right, parent) each minute. Ask if the tree is rooted and if parent pointers are available.
Treat the tree as an undirected graph where each node is connected to its left child, right child, and parent. This allows fire to spread in all directions.
Use BFS from the target node to compute the shortest time to reach each node. The answer is the maximum distance. Alternatively, use a two-pass DFS to compute the farthest distance in each subtree and combine with the distance from the target.
Write code for BFS or DFS, ensuring O(n) time and O(n) space. Explain how to handle parent pointers if not given (e.g., build adjacency list or use recursion with parent parameter).
Test with target as root, leaf, or internal node. Consider a skewed tree and a balanced tree. Verify the answer for small trees manually.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.