Skip to content
This repository has been archived by the owner on Jul 30, 2020. It is now read-only.

Latest commit

 

History

History
executable file
·
32 lines (19 loc) · 1.03 KB

Validate_BST.md

File metadata and controls

executable file
·
32 lines (19 loc) · 1.03 KB

Validate BST

Problem Statement

You are given a Binary Tree data structure consisting of Binary Tree nodes. Each Binary Tree node has an integer value stored in a property called "value" and two children nodes stored in properties called "left" and "right," respectively. Children nodes can either be Binary Tree nodes themselves or the None (null) value. Write a function that returns a boolean representing whether or not the Binary Tree is a valid BST. A node is said to be a BST node if and only if it satises 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 both of its children nodes are either BST nodes themselves or None (null) values.

Sample input: 10 /
5 15 / \ /
2 5 13 22 /
1 14

Sample output: True

Explanation

We can use a Stack here

Solution

Check this Python code.