Ezvor

1245. Tree Diameter

MediumTree Preparing judge… LeetCode
TreeDepth-First SearchBreadth-First SearchGraph TheoryTopological SortDP on Trees

Hints

Hint 1
Start at any node A and traverse the tree to find the furthest node from it, let's call it B.
Hint 2
Having found the furthest node B, traverse the tree from B to find the furthest node from it, lets call it C.
Hint 3
The distance between B and C is the tree diameter.