As reported: Nutanix MTS-4, 6.5 YoE (2025), round 2 coding: recursively delete leaf nodes in a multi-way tree (an n-ary version of a known onsite question); a long discussion of approaches and their time and space; positive feedback.
A rooted tree has n nodes 0 … n − 1; parent[v] is the parent of v (-1 for the root), and a node may have any number of children. Repeatedly delete all current leaves at once until the tree is empty. Return the nodes deleted in each round, in order of rounds (each round's nodes in increasing order).
Example 1
parent = [-1,0,0,0,1,1,3] 0
/ | \
1 2 3
/ \ \
4 5 6
-> [[2,4,5,6],[1,3],[0]]
Example 2
parent = [-1,0,1,2] (a chain 0 → 1 → 2 → 3) -> [[3],[2],[1],[0]]
Constraints: 1 ≤ n ≤ 10^5; parent describes a single rooted tree.
Code runner format: one JSON value: parent. Implement leafRounds(parent); the harness sorts each round and prints the list of rounds.