**Problem Description**

Given a Binary Tree **A** consisting of **N** integer nodes, you need to find the **diameter** of the tree.

The **diameter** of a tree is the number of edges on the longest path between two leaves in the tree.

0 <= N <= 10^{5}

First and only Argument represents the root of binary tree **A**.

Return an single integer denoting the diameter of the tree.

Input 1:

1 / \ 2 3 / \ 4 5

Input 2:

1 / \ 2 3 / \ \ 4 5 6

Output 1:

3

Output 2:

4

Explanation 1:

Longest Path in the tree is 4 -> 2 -> 1 -> 3 and the number of edges in this path is 3 so diameter is 3.

Explanation 2:

Longest Path in the tree is 4 -> 2 -> 1 -> 3 -> 6 and the number of edges in this path is 4 so diameter is 4.

NOTE:You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.

Sign Up

to access hints and editorial solutions for**Diameter of Binary Tree**

to access hints and editorial solutions for

Loading...