← All problems
Diameter of Binary Tree
Given a binary tree, find the length (in edges) of the longest path between any two nodes. The path need not pass through the root. This is the tree's diameter.
Complexity
Time O(n), Space O(h)
Common pitfalls
- Returning the path instead of its length
- Counting nodes instead of edges
Your solution
Log in to save your code and track progress.