Is_balanced | Binary tree

one of the test case is not passing

@vivekpatel, you are not computing height of the current subtree

i have corrected your code :-

pair<int,bool> isHeightBalancedOptimised(node *root)
{
    pair <int, bool> p;
    if(root == NULL){
        p.first = 0;
        p.second = true;
        return p;
    }
    pair <int,bool> p1 = isHeightBalancedOptimised(root->left);
    pair <int, bool> p2 = isHeightBalancedOptimised(root->right);
    if(abs(p1.first - p2.first) <= 1 && p1.second && p2.second){
        p.second = true;    
    }
    else{
        p.second = false;    
    }
    // Computing height of the current subtree
    p.first=1+max(p1.first,p2.first);   
    return p;
}

In case of any doubt feel free to ask :slight_smile:
mark your doubt as resolved if you got your answer

thanku
how long you have been doing competitive programming