ByteByteGo logo
menuProblems List

Binary Search Tree Validation

Medium

Verify whether a binary tree is a valid binary search tree (BST). A BST is a binary tree where each node meets the following criteria:

  • A node's left subtree contains only nodes of lower values than the node's value.

  • A node's right subtree contains only nodes of greater values than the node's value.

Example:

Output: False

Explanation: This tree has two violations of the BST criteria:

  • Node 5's left subtree contains node 6, and node 6's value is greater than 5.
  • Node 7 has a left child with the same value of 7.

You can practice coding exercises online by logging into bytebytego.com on your laptop.