Problem · Tree

Validate Binary Search Tree

Learn this problem
MediumAtlassian logoAtlassianFULLTIMEOA

Problem statement

Return whether the binary tree is a valid binary search tree. Every value in a left subtree must be strictly smaller than its ancestor, and every value in a right subtree must be strictly larger.

Function

isValidBST(root: TreeNode) → boolean

Examples

Example 1

root = [2,1,3]return = true

Both children satisfy the strict bounds imposed by the root.

Constraints

  • The tree contains between 1 and 10000 nodes.
  • Node values fit in a signed 32-bit integer.

More Atlassian problems

drafts saved locally
public boolean isValidBST(TreeNode root) {
  // Write your code here.
}
root[2,1,3]
expectedtrue
checking account