← All problems

Validate Binary Search Tree

medium

Given the root of a binary tree, determine whether it is a valid binary search tree: every node's value must be strictly greater than all values in its left subtree and strictly less than all values in its right subtree.

Pairs well with the BST insert visualization — this problem asks you to verify the invariant that visualization builds.

Example

Input: root = [5, 1, 4, null, null, 3, 6]
Output: false        // 4's left subtree contains 3, but 4 is the right child of 5's... actually 3 < 4 is fine; the violation is that 4 < 5 but sits in 5's right subtree.
Loading...