Given a binary tree, explain how you would determine if it is a valid Binary Search Tree (BST).
A valid BST has these properties: - The left subtree of a node contains only nodes with values less than the node's value. - The right subtree contains only nodes with values greater than the node's value. - Both left and right subtrees must also be valid BSTs.
For example:
Valid BST: Invalid BST:
5 5
/ \ / \
3 7 3 7
/ \ / \
1 4 1 6 (6 > 5, violates BST property)A common mistake is only checking immediate children. How do you avoid this?
Explain your approach and analyze the time and space complexity.
How to approach it
- Hint 1
Simply checking if left child < node < right child is not sufficient. A node deep in the left subtree could be greater than the root.
- Hint 2
Pass down valid ranges (min, max) as you recurse. Each node must fall within its allowed range.
- Hint 3
Alternatively, an in-order traversal of a valid BST produces values in strictly increasing order.
Ready to answer it out loud?
Record your answer in 1:30 and Preptile scores it 1–10 with specifics — what landed, what you skipped, and what to say next time.
Practising needs an invite code. Join the waitlist and we’ll send you one.