int maxx(Node* root,int res)
{
    if(root==NULL)return INT_MIN;
    if(root->left!=NULL){
        if(root->left->data>res)res=root->left->data;
    }
    if(root->right!=NULL){
        if(root->right->data>res)res=root->right->data;
    }
    
    return max({res,maxx(root->left,res),maxx(root->right,res)});
}

int minn(Node* root,int res)
{
    if(root==NULL)return INT_MAX;
    if(root->left!=NULL){
        if(root->left->data<res)res=root->left->data;
    }
    if(root->right!=NULL){
        if(root->right->data<res)res=root->right->data;
    }
    
    return min({res,minn(root->left,res),minn(root->right,res)});
}

bool isBST(Node* root) {
   if(root==NULL)return true;
   int mini=minn(root->right,INT_MAX);
   int maxm=maxx(root->left,INT_MIN);
   if((mini>root->data) && (maxm<root->data))return (isBST(root->left) && isBST(root->right));
   else return false;
}