Mid
Detailed answer
Trees
DSA & Coding Interviews
How do you validate a Binary Search Tree?
Short answer: Each node must lie within an allowed (low, high) range. Recurse left with high = node.val and right with low = node.val. Alternatively, inorder traversal must produce a strictly increasing sequence.
Complexity
Time O(n), Space O(h) recursion height.
Mistakes to avoid
- Only comparing with immediate children (misses deeper violations)
- Using ≤ when duplicates are not allowed
Pass long.MinValue/MaxValue (or nullable bounds) to avoid int overflow edge cases.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png