Skip to content

Files

is-valid-bst

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Mar 8, 2023
Mar 7, 2023

Given a binary tree, write a function to test if the tree is a binary search tree.

You can assume that there will only be integers value.

Each BST node has an integer value, a left child node, and a right child node. A node is said to be a valid BST node if and only if it satisfies the BST property: its value is strictly greater than the values of every node to its left; its value is less than or equal to the values of every node to its right; and its children nodes are either valid BST nodes themselves or None / null.

Sample Input

tree =    5
       /     \
      2       7
    /   \   /   \
   1     3 6     8

Sample Output

true