Solution: Height of Binary Tree After Subtree Removal Queries
Understand how to compute the height of a binary tree after several subtree removal queries. Explore using depth-first search to record node depths and heights, grouping nodes by depth to optimize height recalculation. This lesson helps you handle dynamic tree height changes efficiently with DFS traversal and dictionary lookups.
We'll cover the following...
Statement
We are given the root of a binary tree with queries, of size
Note: A tree’s height is the number of edges in the longest path from the root to any leaf node in the tree.
A few points to be considered:
All the values in the tree are unique.
It is guaranteed that
queries[i]...