FDEInterviews logoFDE/Interviews
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.

Unlock the other 466 answers · ₹2,000 / $25Your progress and mastery stay saved · 6 months · one payment · no auto-renew
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.