why my code is fail in 1 2 test case plzz correct my code
Print all node at distance k
@Pranav7g
This is the updated code.
There were some errors in your code.
- Take input in an identifier with a different name. Helps maintain clarity.
- 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.
- In the if statement where dr != -1, you were making a call with k - dl - 2 as an argument. Correct that.
- 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.