FDEInterviews logo
Coding & DSA / 81
medium★ EssentialAmazonMetaGoogle

Validate a binary search tree

Almost everyone writes the version that only compares each node to its immediate children, and almost every interviewer has a counterexample ready. The fix is to carry a valid (low, high) range down the recursion, or to check that an inorder traversal is strictly increasing.

Updated Aug 2026 · Grounded in real Forward Deployed Engineer interview loops and written to a senior-engineer editorial bar.

Almost everyone writes the version that only compares each node to its immediate children, and almost every interviewer has a counterexample ready. The fix is to carry a valid (low, high) range down the recursion, or to check that an inorder traversal is strictly increasing.

20 answers per topic instead of 10, plus saved progress and bookmarks · no cardor unlock all 528 remaining answers · ₹2,000 / $25
UP NEXT ON YOUR JOURNEY
FEDITOR'S NOTE

The whole question exists to catch one bug: comparing a node only to its direct children. That passes shallow trees and fails on a grandchild that violates an ancestor's bound, which is exactly the input the interviewer feeds you. The strong answer carries an open interval down the recursion. The inorder approach is the elegant alternative and a good thing to mention; an interviewer who sees both knows you understand why the BST property is global, not local.

DISCUSSION · 0

No comments yet — be the first to share your approach.