Back to problems

Height of an N-ary Tree After Node Deletions

Algorithm · Snowflake · Medium

You are given a rooted tree in which each node may have any number of children, together with a collection deleted of node values to remove. Compute the height of the tree after all of those nodes have been removed. A removal works like this: When a node u is removed, every child of u is reattached directly to the parent of u. Removing a node never removes the nodes below it; its whole subtree stays in the tree. All node values are distinct, and the root is never among the…

Loading the rest of the question…