dsa · easy

Diameter of Binary Tree

The **diameter** of a binary tree is the number of **edges** on the longest path between any two nodes. The path may or may not pass through the root.

Arguments

Each node is [value, left, right] or None.

Example

[1,[2,[4,None,None],[5,None,None]],[3,None,None]]3 (path 4-2-1-3 or 5-2-1-3).

[1,[2,None,None],None]1.

Constraints

1 <= number of nodes <= 200 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[1,[2,[4,None,None],[5,None,None]],[3,None,None]]

Expected:
3

Example 2

Input:
[1,[2,None,None],None]

Expected:
1

Open in the Dojo editor