← Questions
Delete leaves with a target value, repeatedly
0
I was asked this
No reports yet. Sign in to say where you were asked it.
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.
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
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
