Data Structures19 sections · 729 units
Open in Course

Problem - Delete Node in BST

Maintain BST property

Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated). The deletion you can divide into two stages:

1.1. Search for the node to delete

2.2. If found, delete the node Example: Deleting 3 from [5,3,6,2,4,null,7][5,3,6,2,4,null,7] produces [5,4,6,2,null,null,7][5,4,6,2,null,null,7] (one valid answer). Constraints: up to 10410^4 nodes, values from 105-10^5 to 10510^5.