Diameter of the tree (optimized approach)

sir here why do we return the height if we just need the diameter?
why do not we just return the diameter if we just want to calculate the diameter?!!

This is self understood , i think you want to something else
suppose if tree is like this

       1
     /   \
    2     3
   /    
  4     

then diameter of the tree is not this, this is width

       1
     /   \
    2     3
   /    
  4     
|____________|

diameter is this

       1
    //  \\
    2    3
  //    
  4     

The diameter of a tree (sometimes called the width) is the number of nodes on the longest path between two end nodes.

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.