Skip to content
Discussion options

You must be logged in to vote

The problem asks us to delete all leaf nodes in a binary tree with a specified value. If, after deleting a leaf node, its parent node becomes a leaf with the same value, we must continue deleting such nodes recursively until no more can be deleted.

Key Points

  • A leaf node is a node with no children (both left and right child are null).
  • The target value is the value of the leaf node we want to delete.
  • After deleting a leaf, check if its parent node becomes a leaf with the target value, and if so, delete that too.

Approach

  1. Recursive DFS (Depth-First Search):
    We will traverse the tree using a depth-first search. At each node, we check:
  • If the current node is a leaf (both left and right c…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Jan 17, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants