Easy · Trees
Diameter of Binary Tree
Given the root of a binary tree, return its diameter: the number of edges on the longest path between any two nodes (0 for an empty or single-node tree).
Examples
Example 1
[1,2,3,4,5]Output: diameter 3
Example 2
{
"tree": [1, 2, null, 3]
}Output: diameter 2
Rebuild it in the studio
Core interview problems are free with a full runner and lessons; Pro opens the complete library.