InterviewBit Academy is now Scaler!
Learn Tech Skills from Scratch @ Scaler EDGE

Valid Binary Search Tree

Given a binary tree, determine if it is a valid binary search tree (BST).

Assume a BST is defined as follows:

  1. The left subtree of a node contains only nodes with keys less than the node’s key.
  2. The right subtree of a node contains only nodes with keys greater than the node’s key.
  3. Both the left and right subtrees must also be binary search trees.

Example :

Input : 
  /  \
 2    3

Output : 0 or False

Input : 
 / \
1   3

Output : 1 or True 

Return 0 / 1 ( 0 for false, 1 for true ) for this problem


Complete solution in the hints.

NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Valid Binary Search Tree on Interview Code Editor
  • Complete Solution
Asked In:


Click here to start solving coding interview questions