#5 most askedVery commonMediumBST
Validate Binary Search Tree
New to BST? Learn it from scratch firstBinary Search Trees in Depth โ
๐ข Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.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.
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.