Binary Search Tree/Medium

Validate Binary Search TreePRO PASS

Time: O(N)Space: 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 / 333%
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
}

Custom Test Case Runner

Input your custom values and visualize step-by-step trace

Quick Presets:

AI DSA Coach

Contextual Tutor for Validate Binary Search Tree

Hello! I am your AI DSA Tutor for **Validate Binary Search Tree** (Binary Search Tree). Ask me anything about this algorithm, time complexity, or request a step hint!