I knew House Robber III going in so my first instinct was to just start coding the DP.
Define a TreeNode class with a value and a list of children, then use tree DP where each node returns two values: the maximum sum when the node is selected (including its value plus the 'not selected' sums of its children) and when it is not selected (sum of the maximum of the two states for each child). The answer is the maximum of the two states at the root.
Pro tip: Clarify whether node values can be negative; if so, adjust the DP to allow skipping nodes (e.g., max(0, ...) for not selected). Also, mention that the DP can be implemented iteratively with post-order traversal to avoid recursion depth issues.
Create a class for the n-ary tree node with a value field and a list of children. This sets up the data structure for the problem.
For each node, define two states: dp[node][0] = max sum when node is not selected, dp[node][1] = max sum when node is selected. Explain the recurrence relations.
If node is selected, its children cannot be selected, so dp[node][1] = node.val + sum(dp[child][0]). If node is not selected, children can be either selected or not, so dp[node][0] = sum(max(dp[child][0], dp[child][1])).
Use post-order traversal (DFS) to compute children's DP values before the parent. This can be done recursively or iteratively with a stack.
After processing all nodes, the answer is max(dp[root][0], dp[root][1]). Handle edge cases like empty tree or negative values.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.