Tree DFS
LC #98Medium
Validate Binary Search Tree
Tree DFS
AmazonGoogleMetaMicrosoftProblem
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
Input
root = [5, 1, 4, null, null, 3, 6]Output
falseWhy
Root is 5 but right child is 4 (4 < 5 violates BST property)