Classic DP problem and I knew it, which was both good and bad.
Recognize this as the classic House Robber problem and solve it using dynamic programming. Define a recurrence where the maximum at each house is the max of skipping it or robbing it plus the max from two houses back, then optimize space to O(1).
Pro tip: Start by clarifying edge cases (empty array, single house) and then mention that the DP can be optimized to constant space, showing you think about efficiency beyond the basic solution.
Restate the problem to ensure understanding, confirm constraints (e.g., non-negative integers, array size), and discuss edge cases like empty array or single house.
Explain that the maximum at house i depends on the maximum up to i-1 (skip house i) or the maximum up to i-2 plus house i (rob house i).
Write the recurrence: dp[i] = max(dp[i-1], dp[i-2] + nums[i]), with base cases dp[0] = nums[0], dp[1] = max(nums[0], nums[1]).
Observe that only the last two DP values are needed, so replace the array with two variables to achieve O(1) space.
Code the solution, then walk through a small example (e.g., [2,7,9,3,1]) to verify correctness and discuss time complexity O(n).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.