Challenge: Delete Node

Let’s delete a node in a BST.

Problem

Remove the node x from a BST and reorganize nodes of the BST to maintain its necessary properties.

Input

A value x that needs to be deleted.

Output

The DeleteNode() function will simply delete the node.

Sample input

4

Sample output

Let’s suppose we have the following tree:

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.