Print all nodes at distance k from a given node


giving wrong answer

Hey Dhairya, you forgot to return 1+dr in line 103.

yes, added
still getting wrong answer

Also in line 97 condition must be dr+1==k,
your answer then is correct but it doesnot matches the order of backend!(for example if answer of one of the query is 12 45 67, your answer is 45 67 12)
so your code is fine, just take care that output must be in sorted order, for this just save answer in a container and then sort it before printing.


edited code as you said, still getting wrong answer in 3 test cases


see it works fine now!

  1. use multiset (as duplicate values might be there!)
  2. return 1+dr

@mayankA47 thank you, got it