Mental Model
The diameter of a tree is the longest path between any two nodes. We find it by checking the longest paths through each node using dynamic programming.
Analogy: Imagine a network of roads connecting cities. The diameter is the longest route you can take between two cities without repeating roads. We find it by looking at the longest roads from each city and combining them.
1
/ \
2 3
/ \
4 5
Each number is a city (node), lines are roads (edges).