Skip to content
CampusEduX

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.

Related Problems

  • Check Balanced Binary Tree
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Lowest Common Ancestor
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Zigzag Level Order Traversal
    Medium · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...