Zero To DSAZero To DSA
Privacy Policy
Binary Tree Inorder TraversalLowest Common Ancestor of BST

Validate Binary Search Tree

medium
Time: O(n)
Space: O(h)

Given the root of a binary tree, determine if it is a valid BST.

Constraints

  • The number of nodes is in the range [1, 10⁴].

Examples

Input: root = [2,1,3]
Output: true
Input: root = [5,1,4,null,null,3,6]
Output: false
Root value 5 with right child 4 violates BST property.