AlgoFrames

Spot the bug: lost subtree

Standard · Find the bug · about 8 min

This delete loses keys for some inputs. Click the line with the bug, then fix it.

Example 1

Input:

[[5,3,6,2,4,null,7],6]

Output:

[5,3,7,2,4]

The buggy code returns [5, 3, null, 2, 4] here: 7 is lost.

Constraints

  • 0 ≤ number of nodes ≤ 1,000
  • Keys are distinct integers with 0 ≤ key ≤ 1,000
  • The tree is a valid BST, given in level order; null marks a missing child

Learn the idea first: BST delete; successor and predecessor, a visual lesson.

More BST delete; successor and predecessor problems