Why wrong answer is coming

@ayushwahi3005
Dont set values using the ouside val variable. Instead let the distance of parent nodes be a guide to the values of the children nodes. Declaring the outside val is wrong because suppose there are many siblings. Then the distance of their children must be same from the src node. But according to your logic, the distance will keep on increasng. Just correct this.

If my answer is able to clear your query, please mark the doubt as resolved.