The Diameter of N-Ary Tree interview question is the general version of the binary tree diameter problem. You need to find the longest path between any two nodes in a tree where each node can have any number of children.
Goldman Sachs and Meta use this to see if you can generalize a binary tree algorithm. It evaluations your ability to use sorting or selection to find the "Top 2" values among many. It tests whether you can handle iterative child processing within a recursive structure.
This uses DFS with a "Top Two" selection logic.
maxDiameter.largest_height + 1 to the parent.Node A has children B, C, D.
To find the two largest numbers in a list in , use two variables (max1, max2) and update them as you scan. This is a common sub-task in many "Hard" coding problems.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Find the Last Marked Nodes in Tree | Hard | Solve | |
| Maximum Number of K-Divisible Components | Hard | Solve | |
| Move Sub-Tree of N-Ary Tree | Hard | Solve | |
| Count Nodes Equal to Sum of Descendants | Medium | Solve | |
| Distribute Coins in Binary Tree | Medium | Solve |