BETA
Deletion in a Binary Tree
Submissions: 2737   Accuracy:

13.34%

  Difficulty: Easy
     

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 not is replaced by bottommost and rightmost node).
Example:


Input:
The function takes two arguments as input, the reference pointer to the root of the binary tree and an integer Key that needed to be deleted from the tree.
There are T test cases and for each test case the function will be called separately.

Output:
For each test output will be the inorder traversal of the new tree.

Constraints:
1<=T<=100
1<=N<=103


Example:
Input:

2
7
10 20 L 20 30 L 30 40 L 30 50 R 40 60 L 60 70 R 70 80 L
40
6
1 2 L 1 3 R 2 4 L 2 5 R 3 6 L 3 7 R
6
Output:
60 70 80 30 50 20 10 
4 2 5 1 7 3 

Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Harshit Sidhwa
Author: harshitsidhwa


Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.