Classic DP problem and I knew it the second I read it.
Clarify the problem and constraints, then explain that this is a dynamic programming problem where for each house you decide to rob it (and add the max from two houses back) or skip it (keeping the previous max). Derive the recurrence maxRob(i) = max(maxRob(i-1), maxRob(i-2) + nums[i]) and optimize space to O(1) by keeping only the last two values.
Pro tip: After presenting the optimal solution, mention that the same pattern solves House Robber II (circular street) by splitting into two linear cases, showing you understand the underlying DP pattern rather than just memorizing one problem.
Restate the problem in your own words and ask clarifying questions: Can the array be empty? Are all numbers non-negative? Is the array circular? Confirm that robbing adjacent houses is forbidden.
Define dp[i] as the maximum amount robbable from the first i houses. Derive the recurrence: dp[i] = max(dp[i-1], dp[i-2] + nums[i]), with base cases dp[0] = 0 and dp[1] = nums[0].
Trace the recurrence on a small example like [2,7,9,3,1] to demonstrate correctness and build intuition. Show how the decision to rob or skip each house leads to the optimal total.
Observe that dp[i] only depends on the previous two values, so replace the DP array with two variables (prev2 and prev1) to achieve O(1) space. Update them iteratively.
State that the time complexity is O(n) and space is O(1). Handle edge cases: empty array returns 0, single house returns its value, two houses return the max of the two.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.