Help with error

code: https://ide.codingblocks.com/s/423228

prob: https://hack.codingblocks.com/app/contests/2022/350/problem

gettng seg fault I’m pretty sure the logic is correct , also the tree is getting built properly so the error must be from the findkDistance or it’s helper funciton

Hello @raghav007 please wait i am checking your code.

@raghav007 you are not checking for this condition in your function findkdistance: if (root == NULL) {

    return 1;

}

one number is missing in the output, I updated the above code

i have made all the changes :

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.