Back to problems

Compute height of tree with deleted nodes; minimize deletions

Algorithm · Snowflake · Hard

You are handed a rooted tree in which every node stores the list of its children. Nodes are numbered from 0 to n - 1, and node 0 is the root whenever n > 0. Along with the structure you receive a boolean array deleted of length n; an entry set to true marks that node as removed. A removed node may never be entered while traversing, and every descendant that consequently loses its link to node 0 is dropped from consideration. The part still reachable from the root is what we…

Checking your access…