Validate Binary Search Tree
Problem
Given the root of a binary tree, decide whether it is a valid binary search tree. A valid BST requires, for every node, that every value in its left subtree is strictly less than the node's value and every value in its right subtree is strictly greater, and that both subtrees are themselves valid BSTs. Return True or False.
- The tree has between 1 and 40,000 nodes.
- Node values are signed 32-bit integers, so the extreme values
-2^31and2^31 - 1can appear as node values (this matters for how bounds are represented).
Examples
root = [8, 3, 12]→True. Left smaller, right larger, nothing deeper to check.root = [10, 4, 9, None, None, 7, 11]→False. The right child 9 is smaller than the root 10.root = [10, 6, 14, None, None, 5, 16]→False. The node 5 is smaller than its parent 14, which is fine locally, but it sits in the right subtree of 10, so it must be greater than 10.
Hints
- Checking each node only against its parent passes the second example and fails the third. What constraint does a grandparent impose?
- As you walk down, every left turn puts an upper bound on everything below, and every right turn puts a lower bound. How many bounds do you actually need to carry?
- Pass an open interval
(low, high)down the recursion; alternatively, an inorder traversal of a BST must be strictly increasing.
Last reviewed 8 September 2026
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.