 All Problems
Delete Node in a BST
medium
trees
binary search tree
amazon
google
microsoft

Given the root of a BST and a key, delete the node with that key and return the updated root. Output the level-order traversal of the result.

Example 1:

Input: 5 3 6 2 4 null 7
Key: 3
Output: 5 4 6 2 null null 7

Example 2:

Input: 5 3 6 2 4 null 7
Key: 0
Output: 5 3 6 2 4 null 7

Input format: Line 1: level-order tree. Line 2: key.

Output format: Level-order with "null" for absent nodes (trailing nulls omitted).

Run to check your code against the sample cases, or submit to run every case