algorythms
Tree DFS
LC #98Medium

Validate Binary Search Tree

Tree DFS
AmazonGoogleMetaMicrosoft

Problem

Determine if a binary tree is a valid BST.

treedfsbst

Constraints

  • 1 ≤ n ≤ 10⁴
  • -2³¹ ≤ Node.val ≤ 2³¹ − 1
  • All values must be strictly less/greater (no equal values)

Example

Inputroot = [5, 1, 4, null, null, 3, 6]
Outputfalse
Why

Root is 5 but right child is 4 (4 < 5 violates BST property)

Hints — reveal one at a time