Diameter shows you the core Tree DP trick: a function that returns one value (height) while computing another (diameter) as a side effect. This "return X, update Y" pattern appears in many tree problems.
The Subordinates problem (CSES ) computed subtree size. Diameter computes subtree height and tracks a global max. Both follow the same template: base case, recurse on children, combine results.