Back to problems

Tree Height After Node Removal

Algorithm · Snowflake · Medium

Problem You are given the root of a tree and a target node. Delete the target node together with every node below it, then return the height of the tree that remains. The height is measured by the number of edges on the longest path from the root to any remaining leaf. An empty tree has height -1. Node values are unique, and target identifies the value of the node to remove. Each node is a binary tree node with fields val, left, and right, where left and right reference…

Checking your access…