Problem 1110 · Medium

Delete Nodes And Return Forest

Walk the tree from the top, cut out each deleted node, and start a new tree below every cut that keeps a node.

Open the interactive visualisation