1522. Diameter of N-Ary Tree
Problem
Return the diameter of an N-ary tree (length of the longest path between any two nodes).
Given the root of an N-ary tree, find the diameter of the tree. The diameter is the number of edges on the longest path between any two nodes in the tree. The path does not necessarily have to pass through the root.
The tree is passed as a flat integer array using a preorder encoding with explicit child counts. For each node, write its value, then the number of children, then recursively encode each child in order. An empty tree is the empty array. Decoding uses a cursor: read the value, read the child count, advance the cursor by two, then decode that many children in order.
1522. Diameter of N-Ary Tree
Return the diameter of an N-ary tree (length of the longest path between any two nodes).