You are given a tree with nodes. Find the diameter: the maximum distance between any two nodes. Input: First line has . Next lines each have two integers and representing an edge. Output: Single integer, the diameter. Constraints: This is the classic tree diameter problem.
Solve it efficiently using two-BFS or DP. Both approaches run in time and teach you core techniques for tree problems.
Space complexity is for the data structures used.