Back to DSA

Validate Binary Search Tree

medium
Acceptance: 42%
BSTBinary Tree

Given the root of a binary tree, determine whether it satisfies the binary search tree property. In a valid BST, every node in the left subtree has a value strictly less than the node, and every node in the right subtree has a value strictly greater than the node. This rule must hold for every node in the tree.

Examples

Example 1:
Input:root = [4,2,6]
Output:true
Example 2:
Input:root = [3,1,5,null,null,2,7]
Output:false

Hints

00:00
1234567