#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