Print all nodes at a distance k from a given node

Please help me to debug my code. Sample test case is passed but cannot pass two test cases after submitting

You need to print the nodes in sorted order. You can create a vector to store all the nodes at distance k and then sort it before printing final answer.

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.

https://ide.codingblocks.com/s/249621 nothing being printed, please help

Update : 2/4 test cases being passed https://ide.codingblocks.com/s/249621

Update: 3/4 test cases being passed

@mohammadabdullahjawwad read problem statement carefully you have to Print 0 if no such node exist at distance k.

Made the change. Still one test case not being passed. Please help.

your code was still not printing 0 so i have made a small change in your code look at this https://ide.codingblocks.com/s/250005

Thanks, it worked. But why wasn’t my code printing zero, result vector was anyway empty. Please explain

@mohammadabdullahjawwad you were checking if ans exist then print else print 0 but your answer was never returning NULL.

But the return type of answer was int, how could it return NULL?

i mean you were cheking if(answer(---------)) then print but your answer was never returning 0 so it will always go in the first if condition and hence does not print 0.

Okay, got it! Thanks man @sdevwrat

1 Like

mark this doubt as resolved if you don’t have any further queries.

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.