You are given the root of a binary tree. Your task is to determine whether it is a valid Binary Search Tree (BST).
A BST is considered valid if, for every node:
Return true if the tree satisfies all BST properties; otherwise, return false.
Input: root = [2,1,3]
Output: true
Explanation: Every node satisfies the Binary Search Tree property.
Input: root = [5,1,4,null,null,3,6]
Output: false
Explanation: The node with value 3 is in the right subtree of 5 but is smaller than 5, violating the BST property.
Input: root = []
Output: true
Explanation: An empty tree is considered a valid Binary Search Tree.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
2 1 3
true
50 30 70 20 40 60 80
true