← Snowflake Interview Insights
The promotion logic is where I got tangled.
Use a post-order DFS to process the tree bottom-up, deleting nodes and promoting their children to the parent. At each node, compute the height of the resulting subtree after deletions, and return the maximum height of the root's subtree.
Pro tip: Clarify with the interviewer whether the height should be computed after all deletions or if deletions can be done in any order; also discuss edge cases like deleting a leaf or a node with multiple children.
Confirm that the root is never deleted, and that height is measured in edges. Clarify that deletions are simultaneous and children are promoted to the deleted node's parent.
Use post-order DFS because deletions affect the subtree structure, and we need to compute heights bottom-up after modifications.
For each node, recursively process its children. If the node is to be deleted, return its children's processed results to be attached to its parent; otherwise, compute its height as 1 + max(children heights).
When a node is deleted, its children (after their own deletions) are promoted to the parent. Ensure the parent's children list is updated accordingly.
After processing the root, return the maximum height of the resulting tree. If the root has no children, height is 0.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.