Tap here to switch tabs
Problem
Submissions

Problem: Delete Node in a BST

Delete Node in a BST asks you to remove a specified value from a binary search tree and return the updated tree while preserving its ordering property.

Statement

Given the root of a binary search tree and an integer key, remove the node with value key from the tree, and return the root of the updated binary search tree.

The deletion consists of two main stages:
11. Locate the node containing the value key.
22. If the node exists, delete it while maintaining the binary search tree property.

Constraints:

  • The number of nodes in the tree is in the range [0,104][0, 10^4].

  • −105≤-10^5 \leq Node.val ≤105\leq 10^5

  • Each node has a unique value.

  • root is a valid binary search tree.

  • −105≤-10^5 \leq key ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Delete Node in a BST

Delete Node in a BST asks you to remove a specified value from a binary search tree and return the updated tree while preserving its ordering property.

Statement

Given the root of a binary search tree and an integer key, remove the node with value key from the tree, and return the root of the updated binary search tree.

The deletion consists of two main stages:
11. Locate the node containing the value key.
22. If the node exists, delete it while maintaining the binary search tree property.

Constraints:

  • The number of nodes in the tree is in the range [0,104][0, 10^4].

  • −105≤-10^5 \leq Node.val ≤105\leq 10^5

  • Each node has a unique value.

  • root is a valid binary search tree.

  • −105≤-10^5 \leq key ≤105\leq 10^5