15% off all plans & roadmaps Use code
See plansLeetCode 98 · Solution & editorial
Given the root of a binary tree, determine if it is a valid binary search tree (BST).
Validate Binary Search Tree is a Tree Traversal Patterns (DFS & BFS) problem, in the Recursive Inorder Traversal subpattern. The pattern covers preorder, inorder, level order traversal, LCA, and serialization
Master inorder traversal for BST validation and kth element problems. Produces sorted order in BST.
The reference solution runs in O(n) time and O(1) space.
Validate Binary Search Tree has been reported in interviews at Amazon, Apple, Asana, Bloomberg, Facebook, Google, Microsoft, Oracle.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Validate Binary Search Tree is a Tree Traversal Patterns (DFS & BFS) problem, in the Recursive Inorder Traversal subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.