Return whether a binary tree is a strict binary search tree: every left descendant must be smaller and every right descendant larger than its ancestor.
Example 1
Argument 1 tree: level-order input; omitted children are null.
Input
root = [4,2,6,1,3,5,7]
Output
true
Explanation
Every left descendant is smaller than its ancestors and every right descendant greater.
Example 2
Argument 1 tree: level-order input; omitted children are null.
Input
root = [5,1,7,null,null,4,8]
Output
false
Explanation
4 is in root 5's right subtree and violates its bound despite being below parent 7.
Example 3
Argument 1 tree: level-order input; omitted children are null.
Input
root = [2,2]
Output
false
Explanation
A child equal to its parent violates strict inequality.
Constraints
1 <= number of nodes <= 10000
Values are signed 32-bit integers
Function contractisValidBSTArguments: tree
Loading draft…
SolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.