A test case is not passing?

in this code there is a function named as height() and it is not giving correct output for this testcase

15
1 3 2 5 4 6 7 9 8 11 13 12 10 15 14

hello @we_kaash

your code is not compiling.

btw is it giving height 1 less than expected height?

i want to compute height of tree without including the root node…thats why i build it in that way but only one test case is not passing i’ve sent it to you already…
and this question is from some other platform if you ask i can send you the link :sweat_smile:

yeah pls share the link and the code that u r submitting over there .
it will help me im debugging

int height(Node* root) {

    if(root==NULL)
    return 0;
    
    static int l=0;
    static int r=0;
    if(root->left!=NULL)
    l=l+1;
    
    if(root->right!=NULL)
    r=r+1;
    
    height(root->left);
    height(root->right);
    return max(l,r);
    }

hello sir there was no response?

your logic is incorrect.

just check this ->

        1
           \
              2
                \
                4
             /
          3
since lefft occured only once, final l will be 1, and final r will be 2

but clearly answer is 3.

simply incrementing  l or r wont work

but sir, the binary tree you made is having height 3( not including the root node as per question’s requirement)

check now…
made correctiom

sir i think you have to provide me the link
please…

…

link of what ?

sorry sir,i thought you made the changes in the code i didnt knew that you can even make changes in the sent messages

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.