Sum at k tree recursion

getting segmentation fault

hi @guptashubham210a input for k is given in the end, but you are taking it in the starting itself. Do look at the input format carefully!

@getting wrong output now

@Ishitagambhir
@getting wrong output now

@guptashubham210a https://ide.codingblocks.com/s/318119

@Ishitagambhir
why this call wasn’t working?
if (k == 0)
{
return root->data;
}
return (root->left, k - 1) + sumatk(root->right, k - 1);

@guptashubham210a try to dry run this for a small tree, you’ll see where this is going wrong

@Ishitagambhir
I am sorry I have tried but not getting where?

@guptashubham210a image
see this line carefully, can you spot the mistake now?

1 Like

@Ishitagambhir
No :joy: :thinking:

@guptashubham210a the function name is missing.
It should be sumatk(root->left, k-1)
instead its just (root->left, k-1)

@Ishitagambhir
I am extremely sorry thats a huge blunder. :blush:

@guptashubham210a dont forget to mark the doubt as resolved!