| Topic | Difficulty | Companies |
|---|---|---|
| Binary Search Tree | MEDIUM | Google Microsoft Amazon Adobe |
Given a binary tree, write a program to check if it is a valid Binary Search Tree(BST).
Problem Note
A BST has the following properties:
Example 1
5
/ \
3 6
/ \
2 4
/
1
Input: [5, 3, 6, 2, 4, -1, -1, 1, -1, -1, -1, -1, -1]
Output: 1
Explanation: Every node satisties the properties of a BST.
Example 2
10
/ \
5 4
Input: [10, 5, 4]
Output: 0
Explanation: The root node's value is 10 but its right child's value is 4.