14. House Robber
easyAsked at IntuitGiven an array representing the loot at each house, maximize the loot you can steal without taking from two adjacent houses. Intuit asks this as a gateway DP problem and reframes it as 'maximum non-adjacent dividends to schedule' for accounting candidates.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Intuit loops.
- Blind (2026-Q1)— Intuit onsite — DP screen following the 'cash-flow scheduling' framing.
- LeetCode Discuss (2025-08)— TurboTax SWE screen — interviewer asked O(1) space follow-up.
Problem
You are a robber planning to rob houses along a street. Each house has a certain amount of money stashed. The only constraint is that adjacent houses have security systems connected, and it will automatically contact the police if two adjacent houses were broken into on the same night. Given an integer array nums representing the amount of money at each house, return the maximum amount you can rob tonight without alerting the police.
Constraints
1 <= nums.length <= 1000 <= nums[i] <= 400All values are integers (think dollars, not cents-with-decimals).
Examples
Example 1
nums = [1,2,3,1]4Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3). Total = 1 + 3 = 4.
Example 2
nums = [2,7,9,3,1]12Explanation: Rob house 1 (2) + house 3 (9) + house 5 (1) = 12.
Approaches
1. Naive recursion
At each house, take it (and skip the next) or skip it; recurse both branches.
- Time
- O(2^n)
- Space
- O(n)
function rob(nums, i = 0) {
if (i >= nums.length) return 0;
return Math.max(nums[i] + rob(nums, i + 2), rob(nums, i + 1));
}Tradeoff: Exponential blowup from re-solving the same suffix. Memoize or convert to DP.
2. Rolling two-variable DP (optimal)
Let take = best when robbing the current house; skip = best when not. Transition: new_take = skip + nums[i]; new_skip = max(take, skip). O(1) space.
- Time
- O(n)
- Space
- O(1)
function rob(nums) {
let take = 0;
let skip = 0;
for (const n of nums) {
const newTake = skip + n;
const newSkip = Math.max(take, skip);
take = newTake;
skip = newSkip;
}
return Math.max(take, skip);
}Tradeoff: Linear time, constant space. Classic textbook DP — interviewers expect this in 5 minutes.
Intuit-specific tips
Intuit reframes this as 'pick non-adjacent dividends to maximize annual return' for accounting-adjacent candidates — same algorithm, different vocabulary. They grade for clean state-transition narration: 'take = previous skip + current, skip = max of previous take/skip.' Bonus signal: solve House Robber II (LC 213, circular) by running the linear version twice — once excluding the last house, once excluding the first.
Common mistakes
- Returning take instead of max(take, skip) — the final house may not be the optimal stop.
- Forgetting that nums can be empty (some variants); guard against length 0.
- Using floats for loot if framed as currency; use integer cents.
Follow-up questions
An interviewer at Intuit may pivot to one of these next:
- House Robber II — houses are arranged in a circle (LC 213).
- House Robber III — houses form a binary tree (LC 337).
- How would you reconstruct the path of robbed houses, not just the total?
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why can we collapse to two variables instead of an O(n) DP array?
The transition only depends on the previous take/skip state, so we never need history beyond i-1. This drops space from O(n) to O(1).
How does this generalize to picking non-adjacent transactions in a ledger?
Same DP. The 'adjacency' becomes a domain-specific constraint (same day, same category), and the values become amounts. The transition is identical.
Practice these live with InterviewChamp.AI
Drill House Robber and other Intuit interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →