Diameter of a tree

test cases are not passing
question–>
https://practice.geeksforgeeks.org/problems/diameter-of-binary-tree/1#
code–>
pair<int,int> diameter1(Node* root) {
pair<int,int> p;
if(root==NULL){
p.first=p.second=0;
return p;
}
pair<int,int> left=diameter1(root->left);

pair<int,int> right=diameter1(root->right);
p.first=max(left.first,right.first)+1;
p.second=max(left.first+right.first,max(right.second,left.second));
return p;
}
int diameter(Node* root){
pair<int,int> p=diameter1(root);
return p.second;
}

@asaurabh_26 are u there?

code is completely correct
just return p.second+1;

pair<int, int> diameter1(Node * root) {
	pair<int, int> p;
	if (root == NULL) {
		p.first = p.second = 0;
		return p;
	}
	pair<int, int> left = diameter1(root->left);

	pair<int, int> right = diameter1(root->right);
	p.first = max(left.first, right.first) + 1;
	p.second = max(left.first + right.first, max(right.second, left.second));
	return p;
}
int diameter(Node * root) {
	pair<int, int> p = diameter1(root);
	return p.second+1;
}

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.