What is the problem in this code. all test cases are not passing

#include
#include
#include
#include
using namespace std;

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

node (int data){
left=NULL;
this->data = data;
right = NULL;
}
};

node * BuildTree(){
int d;
cin>>d;
if(d==-1){
return NULL;
}
node *root = new node(d);
root->left = BuildTree();
root ->right = BuildTree();
return root;
}

int height(node *root){
if(root==NULL){
return 0;
}
int ls = height(root->left);
int rs = height(root->right);
return max(ls,rs)+1;
}

bool check_balance(node *root){
if(root==NULL){
return true;
}
int height_ls = height(root->left);
int height_rs = height(root->right);
if(abs(height_ls-height_rs)<=1){
check_balance(root->left);
check_balance(root->right);
}else{
return false;
}
return true;
}

int main() {
node *root = BuildTree();
cout<<check_balance(root);
}

hello @asifkarim073
pls save ur code here ->https://ide.codingblocks.com/
and share the link with me

image
u need to also consider value return by these function.

if(check_balance(left)==true && checkbalance(right)==true) then return true
otherwise return false.

also correct ur build tree function .(u will be given true or false to indicate presence or absence of the node)

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.