Skip to main content
← Problem catalogue Understand the pattern. Try it yourself. Review the solution. Practice this pattern →
Medium Dynamic Programming High frequency Solution Available Practice Mode

House Robber LeetCode Solution

Tags: #Array #DP

Approach Summary

At each house: either rob it (prev_prev + current) or skip it (prev). Track two previous values.

Practice Mode 2 Progressive Approaches

Solve it yourself before revealing the code

DSA interviews test reasoning from brute force to optimal. Think through the constraints first.

Algorithmic Pattern

Master the Dynamic Programming Pattern

View Pattern Guide →

Study the core invariant, step-by-step decision framework, and common interview traps for the Dynamic Programming pattern.

Framework: Dynamic Programming • Interview Prep: Tested at FAANG • Explore all Dynamic Programming problems & invariants →

How to Recognize This Pattern

  • Cannot take adjacent elements
  • Max sum with gap-1 constraint

Complexity Analysis

Time Complexity

O(n)

Space Complexity

O(1)

Tags

Array DP

Frequently Asked Questions

What is the optimal time and space complexity for House Robber?
The optimal solution for House Robber achieves O(n) runtime complexity and requires O(1) auxiliary space. Time complexity is O(n) as we scan the array in a single linear pass. Space complexity is O(1) when using two running variables.
How do I identify that House Robber requires the Dynamic Programming pattern?
In technical interviews, look for key problem signals: Cannot take adjacent elements; Max sum with gap-1 constraint. Recognizing these invariants allows you to bypass naive brute-force exhaustive search in favor of Dynamic Programming strategy.
What critical edge cases must be handled in House Robber?
Essential edge cases to verify include: Empty array (returns 0); Single house (returns nums[0]); Two houses (returns max(nums[0], nums[1])); All houses have identical values (robs every alternate house). Always walk through these scenarios with your interviewer before coding.
Which tech companies frequently ask House Robber?
House Robber is a Medium-difficulty question tagged with high recurrence. It is actively asked in technical screening and onsite interview loops at Amazon, Google, Airbnb.
Buy me a coffee
Daily Practice
0/0