FastPrepValidate Binary Search Tree

Validate Binary Search Tree

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREENONSITE 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 Bloomberg LP problems

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