Sum_at_kth_level


one testcase is failing

Question is not visible to me, I will reply as soon as question becomes visible.

@swatiguptasg You are not updating the sum using left subtree and right subtree.

> sum+= kthlevel(root->left,k-1);
sum+=kthlevel(root->right,k-1);
return sum; 

Update your code, if this solves your doubt mark it as resolved.

I have made sum as global variable . So why need to update let and right subtree separately.

@swatiguptasg I didn’t see that, if you have made sum as global variable and you are not using it to return anything than make the function type void, otherwise you are having a return type but are not returning anything will cause problem.


Updated code, If this solves your doubt mark it as resolved.

It is still giving one wrong output.

@swatiguptasg the Code I have provided above is your code with two lines modified, Look at it, I have tested the code it passes all test cases.

1 Like