Print all nodes at distance k from a given node

how do i make it print ‘0’ if there is no node at a distance k?

I don’t understand. Your code is already dong that.

Consider this case: 4 60 65 50 70 50 65 60 70 2 65 3 ////////////// 60 1

Consider this case:
4
60 65 50 70
50 65 60 70
2
65 3 //////////////
60 1

Consider this case:
4
60 65 50 70
50 65 60 70
2
65 3 //////////////
60 1

In that case you can take a bool variable flag, set it to false initially.
And whenever you print anything (i.e., whenever you find a node at distance k, turn it true)
After all the calls of this function if the flag variable is still false, that means , you didn’t find any node, so you print 0 in that case , otherwise don’t print 0.

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.