Not able to figure out what's wrong in the code
hey, unable to get ur logic
but a few mistakes that i found
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,IF the logic is correct
https://ide.codingblocks.com/s/242560 reference code
as i mentioned, the sorting problem is still there
another thing
u must check on both sides, u r checking on the right side only when in left the element is not present
if u have a simple tree
1
2 3
then for nodes at distance 1 u need both 2 and 3