Back to problems

Tree Levels After Node Deletions

Algorithm · Snowflake · Hard

Coding Software Engineer You receive the root of a binary tree whose node values are distinct IDs, along with a toDelete array listing the IDs that must be removed. Whenever a node is removed, detach it from the tree and lift each child that exists to the level previously occupied by that node's parent. When deleted nodes occur consecutively along a root-to-leaf route, continue lifting their surviving descendants until they attach to the closest ancestor that remains, or…

Checking your access…