Code-1 is definitely not correct

Code-2 Gives kind-of correct answer but not actually correct as in "Path" we see edges but it gives 1+total edges in the path. we can see this by running on the following tree, code 1 returns 5, while code 2 returns 3 Although the correct answer is 2

1

2 3

4 5

Code-2 Gives kind-of correct answer but not actually correct as in "Path" we see edges but it gives 1+total edges in the path. we can see this by running on the following tree, code 1 returns 5, while code 2 returns 3 Although the correct answer is 2

1

2 3

4 5