Dodomeki
Sign in

74. Validate Search Tree

Medium

Return true if the tree follows the strict search rule: all values on the left of a node are smaller, and all values on the right are larger. The rule applies to all descendants, not just direct children.

Example 1
Input: raiz = [5, 2, 9, 1, 4, 7, 11]
Output: true
Example 2
Input: raiz = [5, 2, 9, 1, 6]
Output: false
Constraints
  • 0 <= quantidade de nós <= 10^4
  • Os valores são inteiros.
TreesBinary search treeDFS
Caso 1
raiz =
[5,2,9,1,4,7,11]
Expected =
true
Caso 2
raiz =
[5,2,9,1,6]
Expected =
false

Run checks these 2 cases. Submit runs all 7, including hidden ones.