#K52057. BST Node Deletion
BST Node Deletion
BST Node Deletion
Given a Binary Search Tree (BST) and an integer key, delete the node with the given key from the BST and return the updated tree. The tree must still satisfy the BST properties after deletion. For a node with two children, replace its value with its in-order successor (i.e. the smallest value in its right subtree) and then remove the successor.
If the key does not exist in the tree, simply output the in-order traversal of the original BST. The in-order traversal of a BST produces a sorted list of numbers.
Note: The BST is provided as a level-order list of values, where the string "null" represents a missing node.
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains a single integer, which is the key to be deleted.
- The second line contains a space-separated list of values representing the BST in level order. The string "null" is used to denote missing nodes. For example:
5 3 7 2 4 6 8
.
outputFormat
Print the in-order traversal of the BST (after the deletion operation) as a space-separated sequence of integers to stdout. If the tree is empty, print an empty line.
## sample3
5 3 7 2 4 6 8
2 4 5 6 7 8
</p>