Skip to content
C

Diameter of Binary Tree

Mediumjavapythonccppjavascript

Find the diameter of a binary tree: the number of edges on the longest path between any two nodes (the path need not pass through the root).

Input Format

The first line contains an integer M, the number of level-order tokens. The second line contains M space-separated tokens (integers or null).

Output Format

Print the diameter, measured in edges.

Input (stdin)

Output

Run your code to see output here...