โ† Trees, Graphs & DP
#5 most askedVery commonMediumBST

Validate Binary Search Tree

New to BST? Learn it from scratch first
Binary Search Trees in Depth โ†’
๐Ÿข Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.
I was asked this

Return True if a tree is a valid BST: every node in the left subtree is smaller, and every node in the right subtree is larger, at every level.

[5, 1, 4, None, None, 3, 6] โ†’ False (3 is in 5's right subtree).

๐Ÿงช Practice

Write your solution, then press Run tests. Explain your approach out loud as you go.

Python
def is_valid_bst(root, low=float("-inf"), high=float("inf")):
    pass

Output appears here. Press Run or Ctrl/โŒ˜ + Enter.

Try it first. Struggling for a few minutes is how it sticks.