The problem itself is fine, classic tree DP.
Use a post-order DFS that returns two values per node: the max loot if you rob this node (node value + grandchildren's non-rob values) and if you don't (max of children's rob/non-rob values). At the root, return the max of the two. This bottom-up DP avoids redundant computation and runs in O(n) time.
Pro tip: Clarify that 'directly connected' means parent-child edges, so you can't rob a node and its immediate children. Mention that the DP state is local to each node, making it a classic tree DP problem.
Confirm that robbing a node means you cannot rob its immediate children, but grandchildren are allowed. Ask about tree size, value ranges, and whether recursion depth is a concern.
For each node, define two values: rob[node] = max loot if robbing this node, and notRob[node] = max loot if not robbing this node. These represent the optimal substructure.
rob[node] = node.val + notRob[left] + notRob[right]; notRob[node] = max(rob[left], notRob[left]) + max(rob[right], notRob[right]). This ensures no two adjacent nodes are robbed.
Traverse the tree recursively, returning a pair (rob, notRob) for each subtree. At the root, return max(rob[root], notRob[root]).
Time O(n), space O(h) for recursion stack. Handle empty tree (return 0), single node (return its value), and skewed trees (consider iterative DFS if recursion depth is an issue).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.