80: Validate binary search tree

Given a binary tree, check is this a binary search tree

Binary search tree is defined as:

  • left subtree of a node contains only nodes with values less than the parent value
  • right subtree of a node contains only nodes with values greater than the parentvalue
  • left and right subtrees must be binary search trees

 

Example 1

Input:         4   
              / \  
             3   5 

Output: true

Example 2

Input:         4   
              / \  
             3   2 

Output: false
Difficulty:Medium
Topic:Tree
Problem #:80