Skip to content
Veltoryx Technologies
ProProblem 100● MediumLeetCode #98 ↗4 min readUpdated 30 October 2026

Validate Binary Search Tree

Validate a binary search tree using top-down ancestor boundary ranges.

01The problem

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 strictly less than the node's key.
  • The right subtree of a node contains only nodes with keys strictly greater than the node's key.
  • Both the left and right subtrees must also be binary search trees.
text
       5
      /      4   6
        /        3   7

Output: false (Node 3 is in right subtree of 5, but 3 < 5!)

Constraints

  • The number of nodes in the tree is in the range [1, 10^4].
  • -2^31 <= Node.val <= 2^31 - 1

Loading the rest of the lesson…