51. Validate Binary Search Tree

Check whether a binary tree is a valid binary search tree: every node’s left subtree holds only smaller values, its right subtree only larger values, and both subtrees are BSTs too.

Example 1

Input: root = [2,1,3]
Output: true

Example 2

Input: root = [5,4,6,null,null,3,7]
Output: false
Explanation: 3 sits in the right subtree of 5, so it must be greater than 5.
Hint 1

Checking only parent vs child is not enough.

Hint 2

Pass down the allowed (low, high) range for each subtree.

TreeBSTDFS