Validate Binary Search Tree
Question
Given the root of a binary tree, determine if it is a valid binary search tree (BST).
A valid BST is defined as follows:
- The left subtree of a node contains only nodes with keys less than the node's key.
- The right subtree of a node contains only nodes with keys greater than the node's key.
- Both the left and right subtrees must also be binary search trees.
Input: root = [2,1,3]
Output: true
Input: root = [5,1,4,null,null,3,6]
Output: false
The root node's value is 5 but its right child's value is 4.
Clarify the problem
What are some questions you'd ask an interviewer?
main.py
Login or signup to save your code.
Bookmark
Reset
Run to test on sample or custom input ยท Submit to grade against all cases
Input
Expected
Actual
Standard OutputScroll down...
Looks like you don't have access yet
Members get the full walkthrough, the working code, and the complexity explained.
Get full accessNot sure what this unlocks? Check out a free pattern section.

Code Solution

Complexity
