X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Deletion in a Binary Tree
Easy Accuracy: 38.05% Submissions: 17325 Points: 2

Given a Binary Tree of size N, your task is to complete the function deletionBT(), that should delete a given node from the tree by making sure that tree shrinks from the bottom (the deleted node is replaced by bottommost and rightmost node).
Example:


Your Task:
You don't have to take input. Complete the function deletionBT() that takes root node of the tree and given node value (Key) as input parameter and return the root of the modified tree.

Example 1:

 

Input:
Key=1
         1
       /   \
      4     7
     / \
    5   6 
Output:
5 4 6 7 

Explanation:
Modified Tree after deletion the 
node with key = 1
     6 
    /  \
   4    7
  /   
 5     
The Inorder traversal of the modified 
tree is 5 4 6 7 


Constraints:
1<=N<=104

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.


to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Deletion in a Binary Tree

Output Window