Is Balanced Binary tree

#include <bits/stdc++.h>
using namespace std;

class node
{
public:
int data;
node *left;
node *right;

node(int d)
{
    data = d;
    left = NULL;
    right = NULL;
}

};

node *build(string s)
{

if (s == "true")
{
    int d;
    cin >> d;
    node *root = new node(d);
    string l;
    cin >> l;
    if (l == "true")
    {
        root->left = build(l);
    }
    string r;
    cin >> r;
    if (r == "true")
    {
        root->right = build(r);
    }
    return root;
}
return NULL;

}
bool tt;
pair<int,bool> isHeightBalancedOptimised(node *root)
{
pair<int,bool>p;
if(root==NULL)
{
p.first=0;
p.second=true;
return p;
}
pair<int,bool>l=isHeightBalancedOptimised(root->left);
pair<int,bool>r=isHeightBalancedOptimised(root->right);
if(abs(l.first-r.first)<=1 && l.second && r.second)
{
p.first=max(l.first,r.first);
p.second=true;
}
else
{
p.first=max(l.first,r.first);
p.second=false;
}
return p;
// Write your code here
}

int main()
{
node *root = build(“true”);

cout << boolalpha << isHeightBalancedOptimised(root).second;

return 0;

}
my one test case is fail plzz help

hello @Pranav7g you have done a very small mistake the length of yout tree uptil at any point should be this p.first=max(l.first,r.first)+1 and not this p.first=max(l.first,r.first).
if you update this line in your two conditions , you will be able to pass every test case .
if you feel your doubt is cleared please mark this doubt as resolved.
i hope i have cleared your doubt .
Happy Learning !!