A BST is valid if every node value lies within a strict range determined by its ancestors.
DFS with bounds (lo, hi). For each node, require lo < val < hi. Recurse left with upper bound val, right with lower bound val.
The bounds encode all ancestor constraints, not just the parent constraint.
A BST is valid if every node value lies within a strict range determined by its ancestors.
DFS with bounds (lo, hi). For each node, require lo < val < hi. Recurse left with upper bound val, right with lower bound val.
The bounds encode all ancestor constraints, not just the parent constraint.