Diameter of a Binary Tree

PHOTO EMBED

Sat Mar 04 2023 06:25:48 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

int mxheight(Node* root)
{
    if(root==NULL) return 0;
    return max(mxheight(root->left), mxheight(root->right))+1;
}
class Solution {
  public:
    // Function to return the diameter of a Binary Tree.
    int diameter(Node* root) {
        // Your code here
        if(root==NULL) return 0;
        int p=mxheight(root->left)+mxheight(root->right)+1;
        return max(p, max(diameter(root->left), diameter(root->right)));
    }
};
content_copyCOPY

https://practice.geeksforgeeks.org/problems/diameter-of-binary-tree/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article