Print all nodes at distance k


all test cases not getting passed…
please see if logic is incorrect

Hey @Bansaljatin05
Your approach is not entirely correct. Please see this
15
12 10 17 22 20 85 74 38 23 64 46 51 65 99 87
10 12 17 20 22 23 38 46 51 64 65 74 85 87 99
10
10 2
17 3
22 4
20 2
23 5
46 4
51 2
65 3
99 1
85 2
Your code fails for this testcase

See this for actual code https://www.geeksforgeeks.org/print-nodes-distance-k-given-node-binary-tree/

If your doubt is resolved please mark it as closed.

https://ide.codingblocks.com/s/192136 now whats the error???

some one please reply???

@Bansaljatin05
Your output is correct now. Just the order of output is not right.
For the test case :
15
12 10 17 22 20 85 74 38 23 64 46 51 65 99 87
10 12 17 20 22 23 38 46 51 64 65 74 85 87 99
10
10 2
17 3
22 4
20 2
23 5
46 4
51 2
65 3
99 1
85 2

Answer needs to be :
17
74 99
23 64
17 85
17 20 87
85
64
23 51 74
85 87
17 20 38 87

1 Like

sir, can you please correct it…I was unable to do it

@Bansaljatin05

If your doubt is resolved please mark it as closed.

now also…1 test failing

@Bansaljatin05
Print 0 when vector size is zero while printing output. Given in question statement,

If your doubt is resolved please mark it as closed.

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.