Please point out the error in my code

My code was not accepted in one of the test cases in gfg
problem was: Diameter of a tree
my code in O(n2) complexity please point out the error

Hello @rudradatta3,

  1. There are so many print statements which are unnecessary.
    Reason:
    Your output format should match with the output format given in the question.

  2. The logic for calculating the diameter w.r.t. the current node as root is wrong.

I have corrected your code:

Hope, this would help.
Give a like if you are satisfied.

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.