Update appNew update is available. Click here to update.
Topics

Check BST

Moderate
0/80
Average time to solve is 30m
5 upvotes
Wipro Limited

Problem statement

Given a binary tree with N number of nodes, check if that input tree is BST (Binary Search Tree). If yes, return true, return false otherwise.

Note:
Duplicate elements should be kept in the right subtree.
Detailed explanation ( Input/output format, Notes, Images )
Constraints :
0 <= Number of edges <= 10^5
Time Limit: 1 second
Sample Input 1 :
3 1 5 -1 2 -1 -1 -1 -1

Sample Output 1 :
true
Sample Input 2 :
5 2 10 0 1 -1 15 -1 -1 -1 -1 -1 -1

Sample Output 2 :
false
Full screen
Console