Concept Flow - DP on Trees Diameter of Tree
Start at any node
Run DFS to find farthest node A
Run DFS from 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
Find diameter by two DFS traversals and use DP to store max depths to compute longest path through nodes.
