Print all node at distance k


why my code is fail in 1 2 test case plzz correct my code

@Pranav7g
Will get back to you asap.

@Pranav7g
This is the updated code.

There were some errors in your code.

  1. Take input in an identifier with a different name. Helps maintain clarity.
  2. Send a vector to the function to store the values because you need to print the nodes in a sorted order. Also you need to put a checker in case their are no suitable values in which case you need to print 0 as it is given in the question.
  3. In the if statement where dr != -1, you were making a call with k - dl - 2 as an argument. Correct that.
  4. In case you reach the end of the function, you should return -1 in place of 0.

If my solution was able to resolve your query, please mark the doubt as resolved.