1522. Diameter of N-Ary Tree
TreeDepth-First SearchDP on Trees
Hints
Hint 1
For the node i, calculate the height of each of its children and keep the first and second maximum heights (max1_i , max2_i).
Hint 2
Check all nodes and return max( 2 + max1_i + max2_i ).
Preparing judge…