Print all nodes at distance k from a given node Java

I am getting a wrong answer for a few test cases
lemme know where my code is wrong

Hi @justformyntra8
your code is giving wrong output for
7
20 8 4 12 10 14 22
4 8 10 12 14 20 22
5
4 2
12 3
22 2
8 1
10 1
your output is 20 12
22
8
20 4 12
12
whereas the correct output is:
12 20
22
8
4 12 20
12

Hi @justformyntra8

as you are not responding to the thread, I am marking your doubt as resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “Ask Doubt” section, when your doubt is resolved.

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.