Given the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST requires every node in the left subtree to have a value strictly less than the node, every node in the right subtree to have a value strictly greater than the node, and both subtrees must also be valid BSTs.
root = [2,1,3]trueroot = [5,1,4,null,null,3,6]falsevalidate(root, −∞, +∞) — root starts with the full valid rangenode == null → return true (null is trivially valid)node.val ≤ min OR node.val ≥ max → return false (range violation)(min, node.val), right with (node.val, max) — range narrows each levelA common mistake is only checking the immediate parent-child relationship. That misses deeper violations — e.g., a node in the right subtree that is smaller than the root. By threading the valid range (min, max) down each call, every node carries the full historical constraint from all its ancestors. Going left means the current value becomes the new ceiling; going right it becomes the new floor. The check is globally correct in a single O(n) pass.