AlgoFrames

Find the violating node

Standard · Trace the algorithm · about 6 min

One key in this tree breaks the BST rule. Follow the range check and answer each question before the step plays.

Example 1

Input:

{"levelOrder":[8,3,10,1,6,null,14,null,null,4,9,13]}

Output:

false

The tree is not a BST.

Constraints

  • The trace uses the tree shown
  • Ranges are open: a key equal to a bound breaks it

Learn the idea first: Validating a BST and the in-order property, a visual lesson.

More Validating a BST and the in-order property problems