Print all nodes at a distance k


bahiya 2 test case galat aara ha
check krna ek baar

Okay i got it, why is it failing test cases. Do one thing. Store all the nodes in a vector and sort them in ascending order before printing them as the output is in sorted format. Do this and you will pass all test cases.


same hi aara ha bhaiya

Not like this. Instead of printing store them in vector. Then sort it and then print from vector.
What you are doing is printing and storing in vector. Instead store in vector. Sort it in ascending order and then print that vector.
Also after printing for a test case, don’t forget to clear your vector to avoid garbage value.

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.