Unable to pass 2 test cases in the problem Largest BST in Binary Tree

I am unable to pass 2 test cases in the proble Largest BST in Binary Tree. My code works fine for the sample I/O given but I still think I am making a mistake in the logic. I am unable to figure it out. Please help.

Here is my code: https://ide.codingblocks.com/s/374017

hello @Yash5646


   if(root->left == NULL)
   {
   	if(root->right->data > root->data)
   	{
   		minval = root->data;
   		maxval = root->right->data;
   		return(make_pair(2, true));
   	}
   	else {
   		maxval = root->data;
   		minval = root->right->data;
   		return (make_pair(0, false));
   	}
   }

   else if (root->right == NULL)
   {
   	if(root->left->data < root->data) {
   		maxval = root->data;
   		minval = root->left->data;
   		return(make_pair(2, true));
   	}
   	else {
   		maxval = root->right->data;
   		minval = root->data;
   		return(make_pair(2, true));
   	}
   }

this cases are wrong.
if left or right is NULL then also there is chance of getting bst of size more than 2.

consider this->
1->2->3->4 (root is 1 and all elements are in right pointers)

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.