FastPrepValidate Binary Search Tree

Validate Binary Search Tree

SambaNova Systems logoSambaNova Systems● MediumNEW GRADONSITE INTERVIEW
Learn

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 SambaNova Systems problems

See SambaNova Systems hiring insights
public boolean isValidBST(TreeNode root) {
  // Write your code here.
}
root[2,1,3]
expectedtrue
Checking account…