Check whether a given binary tree satisfies the BST property.
Constraints
Example
>>> # Example 1: Valid BST >>> root = TreeNode(2) >>> root.left = TreeNode(1) >>> root.right = TreeNode(3) >>> is_valid_bst(root) True >>> # Example 2: Invalid BST (right child equals root) >>> root = TreeNode(5) >>> root.left = TreeNode(1) >>> root.right = TreeNode(4) >>> root.right.left = TreeNode(3) >>> root.right.right = TreeNode(6) >>> is_valid_bst(root) False >>> # Example 3: Empty tree >>> is_valid_bst(None) True
Recent Submissions
No submissions yet — hit Run Tests to try!
Hints