The problem itself is fine, tree DP, nothing shocking.
Use a post-order DFS that returns two values per node: the maximum loot if you rob this node (including its value plus the skip values of its children) and the maximum loot if you skip this node (taking the max of robbing or skipping each child). At the root, return the maximum of the two values. This ensures O(n) time and O(h) space.
Pro tip: Explicitly define the two states (rob vs. skip) and show how they combine at each node; this demonstrates you understand the DP recurrence and can avoid exponential brute force. Also, mention that you can optimize space by returning a pair instead of using a memoization table.
Restate the problem: given a binary tree, find the maximum sum of node values such that no two adjacent (parent-child) nodes are both selected. Confirm that node values are non-negative and that the tree can be large, so an efficient solution is needed.
For each node, define two values: rob (max loot if we rob this node) and skip (max loot if we don't rob this node). Explain that rob includes the node's value plus the skip values of its children, while skip takes the maximum of rob or skip for each child.
Write a post-order DFS that returns a pair (rob, skip) for each node. For a leaf, rob = node.val, skip = 0. For an internal node, compute rob = node.val + left.skip + right.skip, and skip = max(left.rob, left.skip) + max(right.rob, right.skip).
State that the time complexity is O(n) because each node is visited once, and space is O(h) for the recursion stack. Mention that this avoids the exponential brute force of trying all subsets and that no memoization table is needed because the DFS naturally computes each state once.
Walk through a small example (e.g., a tree with three nodes) to verify the recurrence. Discuss edge cases: empty tree (return 0), single node (return its value), and skewed tree (recursion depth O(n)).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.