why it is not passing all test cases?
Print all nodes at a distance k from a binary tree
let me just point out the mistakes
- question demands the answers in sorted order, so store the values in a global vector and sort it in the end and display
- if the vector is empty then u can print -1 that is no nodes present
- 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