880. Check if a Tree is a Valid BST

EasyTreesBSTDFSInorder

Given the root of a binary tree, determine whether it is a valid binary search tree: every node's left subtree contains only smaller values, its right subtree only larger values, and both subtrees are themselves valid BSTs (no duplicate values). Return true or false. The tree is given as a level-order array.

Input: A level-order array of the tree.

Output: Boolean — true or false.

Examples

Example 1
Input: [2,1,3]
Output: true
Explanation: Valid BST ordering.
Example 2
Input: [5,1,4,null,null,3,6]
Output: false
Explanation: 4 in the right subtree is less than 5.
Example 3
Input: [1]
Output: true
Explanation: Single node.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →