As reported: LinkedIn Senior Software Engineer, Systems Infrastructure (Sep 2025), DSA round 2: a question similar to the diameter of a tree whose nodes have
nchildren, then whether two linked lists merge.
Given the root of an N-ary tree, return the length of its diameter: the number of edges on the longest path between any two nodes. The path may or may not pass through the root.
This is LeetCode 1522 — Diameter of N-Ary Tree.
Example 1
root = [1,null,3,2,4,null,5,6]
Output: 3 (5 → 3 → 1 → 2, or 6 → 3 → 1 → 4)
Example 2
root = [1,null,2,null,3,4,null,5,null,6]
Output: 4
Constraints: the depth of the tree is at most 1000; 1 ≤ number of nodes ≤ 10^4.
Code runner format: LeetCode's test-case format, one JSON value per line (one line per argument). The input line is the tree in LeetCode's N-ary level-order format (each group of children is followed by null). Implement diameter(root); the harness prints the result.