Concept Flow - DP on Trees Diameter of Tree
Start at any node
DFS to find farthest node A
DFS from node A to find farthest node B
Diameter = distance between A and B
Use DP to store max depths at each node
Calculate max path through each node
Update global diameter if path is longer
Return final diameter
We start DFS from any node to find the farthest node A, then DFS from A to find farthest node B. The distance between A and B is the diameter. DP stores max depths to compute longest paths through nodes.
