← Questions

Delete leaves with a target value, repeatedly

0
GoogleCodingLast asked Sep 2026

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.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding