mediumTreesPure DSA~24 min
Validate Pricing BST
A price-bucketing index is supposed to be a binary search tree so range lookups stay logarithmic. After a buggy insert, you must verify the structure still satisfies the BST ordering at every node.
Problem
Given the root of a binary tree, return true if it is a valid binary search tree: every node's left subtree holds strictly smaller values and its right subtree strictly larger, recursively.
Input
The root of a tree with n nodes (0 ≤ n ≤ 10^4), shown in level order with null for missing children.
Output
A boolean — true if the tree is a valid BST.
Constraints
- 0 ≤ n ≤ 10,000
- All node values are distinct
- Strict inequality on both sides
Examples
Example 1
Input
root = [2, 1, 3]
Output
true
1 < 2 < 3 holds for the whole tree.
Example 2
Input
root = [5, 1, 4, null, null, 3, 6]
Output
false
The right child 4 is less than the root 5, violating the BST rule.