Problem
You get the root root of a binary tree. In a binary tree, each node has at most two children: a left child and a right child.
Return true if the tree is a valid binary search tree (BST). Otherwise, return false.
The left subtree of a node is its left child and all the nodes below that child. The right subtree of a node is its right child and all the nodes below that child.
In a valid BST, each node meets two rules. All values in its left subtree are smaller than the node value. All values in its right subtree are larger than the node value.
The examples show each tree as a list in level order. This list gives the nodes row by row, from left to right. The value null marks a missing child.
Example 1
- Input:
- root = [10,5,15]
- Output:
- true
Example 2
- Input:
- root = [10,5,15,null,null,8,20]
- Output:
- false
- Explanation:
- Node
8is in the right subtree of the root10, but8is smaller than10.
Example 3
- Input:
- root = [7,7]
- Output:
- false
- Explanation:
- The left child has the same value as the root. A value in the left subtree must be smaller.
Constraints
- 1 <= number of nodes <= 10^4
- -2^31 <= Node.val <= 2^31 - 1
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Binary Search Tree to Greater Sum Tree
Coding · Binary Search Tree · Binary Tree · Depth-First Search
- Closest Binary Search Tree Value
Coding · Binary Search · Binary Search Tree · Binary Tree
- Closest Binary Search Tree Value II
Coding · Binary Search Tree · Binary Tree · Depth-First Search
- Kth Smallest Element in a BST
Coding · Binary Search Tree · Binary Tree · Depth-First Search
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 2 records
Amazon
Leetcode 98. Validate Binary Search Tree
Reported Aug 3, 2026 · 2 source reports
JUNIOR, MID_LEVEL
Source snapshot: Nov 12, 2026
View sourceMicrosoft
Leetcode 98. Validate Binary Search Tree
Reported Jan 17, 2026 · 1 source report
SENIOR
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 2 records
Lyft
Validate Binary Search Tree
Reported date not specified · Source window: 3mo
Source snapshot: Oct 20, 2026
Source frequency score: 79.9. This is not an interview probability.
View sourceLyft
Validate Binary Search Tree