Tree diameter edges

Write codeMedium18 min

Your task

Given a binary tree as a level-order array (null for missing), return the length of its diameter measured in EDGES, the number of edges on the longest path between any two nodes, which need not pass through the root. An empty tree has diameter 0 and a single node has diameter 0.

Examples

tree_diameter(level: list) -> int
Example 1
Inputtree_diameter([1, 2, 3, 4, 5])
Output3