I know i am not supposed to ask these types of question here, but I am stucked and cannot figure out the problem. So, I wrote this code which takes root of the tree as input and check if the given tree is BST or not. But i am failing few test cases and i don't understand why ? If someone can tell me what's wrong in my code that would be very much appreciated. This is the link to question Is This a Binary Search Tree?
Here is the code.
bool checkBST(Node* root) {
if(root == NULL)
return false;
int d = root->data;
bool r1 = true,r2=true;
if(root->left != NULL){
if(d < root->left->data)
r1 = false;
else
r1 = checkBST(root->left);
}
if(root->right != NULL){
if(d > root->right->data)
r2 = false;
else
r2 = checkBST(root->right);
}
return r1 && r2;
}