Algorithm · Ziphq · Hard
A rooted n-ary tree is represented as a list of node records plus a root index. Each record nodes[i] has the form [value, child_indices], where value is a non-negative integer and child_indices is a list of 0-based indices of that node's immediate children. You may select any subset of nodes, but a node and any of its direct children cannot both be selected. Return the maximum possible total value of the selected nodes. Implement maxNonAdjacentTreeSum(nodes, root_index). For…
Checking your access…