Delete from a binary search tree
Deleting a leaf or a node with one child is easy: replace it with that child. A node with two children needs a stand-in that keeps the ordering, and the smallest value in its right subtree fits exactly.
# delete 3 from: 3 has children 1 and 6
# successor: smallest in right subtree -> 6Think before coding
Copy the successor's value into the node, then delete that successor from the right subtree. The successor has no left child, so the second deletion is always one of the easy cases. Work through the example by hand before changing the starter. Decide what should happen for an empty input, a single value and a repeated value where those cases apply. The checks use several inputs so a hard-coded answer cannot stand in for the rule.
Your task
TreeNode(value) is provided. Write delete(root, value) returning the root after removing value. Leave the tree unchanged if value is absent.
The explanation opens here once every check passes.