Concept Flow - DP on Trees Diameter of Tree
Start at any node
Run DFS to find farthest node A
Run DFS from node A to find farthest node B
Diameter = distance between A and B
Use DP to store max depths during DFS
Update diameter with max sum of two depths at each node
Return final diameter
We run DFS twice to find the farthest nodes and use DP to track max depths, updating diameter as max sum of two depths at each node.
