← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Given the root of a Binary Search Tree (BST) and an integer key, delete the node whose value equals key while maintaining the BST property. Return the root of the modified tree.
Deletion must handle three cases: (1) the node is a leaf—simply remove it; (2) the node has one child—replace it with its child; (3) the node has two children—replace its value with either the in-order successor (smallest node in the right subtree) or the in-order predecessor (largest node in the left subtree), then recursively delete that successor/predecessor from its original position. The tree must remain a valid BST after deletion.