You now know ways to find tree diameter:
DP approach (LC ): Recurse on the tree, compute heights, track the maximum left + right sum. Works naturally on binary trees with pointer-based nodes.
Double BFS (CSES ): Run BFS twice from endpoints. Works on any tree given as an adjacency list. Simpler when you do not need subtree information.
Both run in time. The Tree Diameter & Center section covers both in full detail with implementations and walkthroughs.