Print all nodes at a distance k from a binary tree


why it is not passing all test cases?

let me just point out the mistakes

  1. question demands the answers in sorted order, so store the values in a global vector and sort it in the end and display
  2. if the vector is empty then u can print -1 that is no nodes present
  3. u don’t need to find the node, u can apply the same checks on the node’s value
    do these steps and it will pass, the logic is correct
    https://ide.codingblocks.com/s/242560 reference code

hey, @tishya_goyal if your doubt is solved, please mark it as resolved