Binary Search Tree · Medium

Validate Binary Search Tree

O(N) · O(H)

Step 1: Setup & Initialization - Validate BST

Verify node values lie strictly within (min, max) bounds.

Array Elements & Pointers
10
[0]
20
[1]
30
[2]
40
[3]
50
[4]
Live Variables & Invariants
status:Initialized
pattern:Validate BST
Step 1 / 3
33%
Solution Code
1
function isValidBST(root: TreeNode | null, min = -Infinity, max = Infinity): boolean {
2
  if (!root) return true;
3
  if (root.val <= min || root.val >= max) return false;
4
  return isValidBST(root.left, min, root.val) && isValidBST(root.right, root.val, max);
5
}
LeetCode IDE Console

Test Cases

3 cases from Blind 75 & NeetCode 150

Ask for a hint whenever you get stuck.