EvalFrame Technical Mock Interviews & Coding Practice

Validate Binary Search Tree

Medium · Binary Search Tree · Algorithm problem · all problems

Given the root of a binary tree represented as an array in level-order, determine if it is a valid binary search tree (BST). A valid BST is defined as follows: * The left subtree of a node contains only nodes with keys strictly less than the node's key. * The right subtree of a node contains only nodes with keys strictly greater than the node's key. * Both the left and right subtrees must also be binary search trees. **Examples:** ```typescript isValidBST([2, 1, 3]) // true isValidBST([5, 1, 4, null, null, 3, 6]) // false ```

Solve It in the BrowserPractice Explaining It Out Loud

Optimal Approach

  • Time complexity: O(n)
  • Space complexity: O(h)

Visits each node once to verify value boundaries.

Follow-Up Questions Interviewers Ask About Validate Binary Search Tree

  • Why is checking root.left < root.val and root.right > root.val insufficient?
    BST property requires all descendants in the left subtree to be smaller, not just the immediate child.

Practice the full problem with execution, tests, and AI code review in the interactive lab — then rehearse explaining your solution in a live voice mock interview.