Print all nodes at distance k

I am getting segmentation fault. Please help.

@vaishnavtannu
Check the input format correctly. There is no m to be taken as input. So delete line 104 and change line 108 to for(int i = 0; i < n; i++)
Also take cin>>t; after line 121


Please check now. I am still not getting any output.

@vaishnavtannu

  1. Change line 57 to if(root->data == target->data)
  2. Change line 62 to int leftDistance = printNodesAtDistanceK(root->left, k, target); and line 76 to int rightDistance = printNodesAtDistanceK(root->right, k, target);

@vaishnavtannu
Mark this doubt as resolved if you get the logic. Thanks

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.