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.
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.
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.
No comments yet — be the first to share your approach.
