LeetCode 98 Validate Binary Search Tree - Implementation

The approach

Pass min and max bounds through recursion.

function isValidBST(root): def validate(node, minVal, maxVal): if not node: return true if node.val <= minVal or node.val >= maxVal: return false return validate(node.left, minVal, node.val) and
validate(node.right, node.val, maxVal) return validate(root, float('-inf'), float('inf'))

O(n)O(n) time, O(h)O(h) space.