Nodes at distance k from a given node

sir the target node was 4…
here why do we return 0 to the ancestor node(2)
and 1 for ancestor node(1)
although the distance between the target and ancestor 2
is one and same thing the distance between the target and ancestor 1 is 2???
sir please explain me this point because it confused me a lot

We return 0 to ancestor node here because 4 is returning 0 , because for 4 target node is at dist 0
Now 2 have to do computation according to this
Similarly here

but sir the actual distance between node 4 and node 2 is 1(there is an edge between them)
so how can the target node return 0 to its direct ancestor?

Hey @mzk1994
You can code it otherwise as well i.e returning 1 from target node to ancestor node
Sir coded like that subcall returns their distance and then for current call we decide by adding 1
U can code otherwise as well

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.