AAmazon·DSASDE-1Technical Phone Screen
Diameter of a Binary Tree
Problem
Given the root of a binary tree, return the length of the diameter — the longest path between any two nodes (path need not pass through the root).
Example
1
/ \
2 3
/ \
4 5
Output: 3 -- path 4→2→1→3 or 4→2→5
Constraints
- 1 ≤ nodes ≤ 10^4
- Node values are unique
Follow-up
Extend your solution to return the actual path nodes, not just the length.
asked 5 days ago
Follow-up questions (0)
Add a follow-up question they asked
No follow-ups yet. Be the first to add one.