Delete leaves with a target value, repeatedly

0
Remix

Given a binary tree and a target value, delete every leaf that holds the target. If that turns its parent into a leaf holding the target, delete the parent as well, and keep going until no such leaf is left. Return the new root.

Follow-ups: what happens when the root itself has to go, whether one of the conditions in your code is really needed, your test cases, and the time and space.

GoogleTechnical phone screenLast asked Sep 2026
No answer yet. Write the first one; the best answer gets endorsed.