My code is not passing all test cases kindly correct my code highlighting my mistakes.
Trees -- Find sum at k level
You are not building tree correctly
if no of child is 1 then also you are calling for left and right both
which is wrong
correct buildTree() function should be like this
node *buildTree()
{
int d,c;
cin>>d>>c;
node *root=new node(d);
if(c==0)
return root;
root->left=buildTree();
if(c==2)
root->right=buildTree();
return root;
}
Modified Code
1 Like
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.