Print all nodes at distance k(TREES)

only two test cases are passing, Can anyone suggest where i am going wrong here? here’s the link to the code:

Hey @rahulgoindi15
Your code is correct. Just make a change with your output. For each query store the output in a vector. Sort the vector. Then output the result.

i did as you said, but now only 1 case is correct and the rest are wrong
here’s the link: https://ide.codingblocks.com/s/178132

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.

no my doubts were not cleared @Aarnav-Jindal-1059677350830863

Hey @rahulgoindi15 you are connected to me on chat and the issue is with just with one misplaced line of code. That’s why I marked it as closed. If you have any issues you can clear it with me there anytime.

which line? and what is wrong??

@rahulgoindi15
Line 86 and 95
Put values in vector and not output them directly.

still testcase 1 isnt passing…

@Aarnav-Jindal-1059677350830863

@rahulgoindi15
You forgot to add one condition. When there are no nodes at distance K that is size of vector is 0, you need to output zero.

If your doubt will be resolved, please mark it as resolved.