MEDIUMasked at 21 companies

Validate Binary Search Tree

A medium-tier problem at 34% community acceptance, tagged with Tree, Depth-First Search, Binary Search Tree. Reported in interviews at SIG and 20 others.

Founder's read

Validate Binary Search Tree hits your screen and you have maybe 20 minutes left. It's asked at SIG, Citadel, Bloomberg, Microsoft, Oracle, Nvidia, and eight other major firms. On paper it looks simple: check if a tree is a valid BST. In practice, candidates blank on the constraint that every node in the left subtree must be less than the parent, and every node in the right subtree must be greater. The naive approach fails on trees with violations deep in the structure. You need to track the valid range as you traverse. If you hit this problem cold during the OA, StealthCoder surfaces a working solution in seconds, invisible to the proctor.

Companies asking
21
Difficulty
MEDIUM
Acceptance
34%

Companies that ask "Validate Binary Search Tree"

If this hits your live OA

Validate Binary Search Tree is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.

Get StealthCoder
What this means

The trap is thinking local. You check left child less than parent, right child greater than parent, then recurse. That fails because a node can violate the BST property relative to an ancestor, not just its immediate parent. The real algorithm maintains a lower and upper bound as you traverse with DFS. For each node, verify it falls strictly between those bounds, then tighten the bounds as you go left (upper bound becomes current value) or right (lower bound becomes current value). This scales to trees of any shape. The acceptance rate sits at 34 percent because candidates rush into a flawed local check, then debug on the clock. With StealthCoder running invisibly during your assessment, you avoid the rewrite.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Validate Binary Search Tree recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Validate Binary Search Tree interview FAQ

Why does checking just left < parent and right > parent fail?+

A node can be less than its parent but greater than an ancestor it shouldn't be. Example: root 10, left child 5, right-left grandchild 7. The 7 is valid relative to its parent (5) but violates the BST rule that everything in the left subtree of 10 must be under 10. You need to track bounds, not just parent values.

Is this problem still asked at FAANG and tier-one firms?+

Yes. SIG, Citadel, Bloomberg, Microsoft, Oracle, and Nvidia all report it. It's a top-10 BST problem because it forces you to understand the global constraint, not just local structure. Medium difficulty but high cognitive load under OA time pressure.

What's the time and space complexity?+

Time is O(n) because you visit each node once. Space is O(h) for the recursion stack, where h is tree height. In a balanced tree that's O(log n), but a skewed tree can push it to O(n). Both are acceptable for this problem size.

How does this relate to Depth-First Search?+

You traverse the tree with DFS (inorder, preorder, or a custom order). DFS lets you maintain state like the lower and upper bounds as you go deeper. That stateful traversal is what catches violations that a simple breadth-first check would miss.

What's the gotcha with the bounds algorithm?+

You need to use None or negative/positive infinity for initial bounds, not just 0 and tree max. Also, comparisons must be strict (less than, not less-than-or-equal) because node values must be unique in a valid BST. Off-by-one logic here tanks submissions.

Want the actual problem statement? View "Validate Binary Search Tree" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.