Solve House Robber with constant space DP
Reported in Snowflake interview loops. Simple but important recurrence-based DP interview problem.
Interview scenario
Context for Snowflake candidates:
Maximize money robbed from non-adjacent houses in a line.
Model answer
Try answering aloud first
Cover trade-offs, structure, and a concrete example before revealing the baseline response.
How to frame this at Snowflake: Connect your answer to measurable impact, clarity of thought, and trade-offs the team cares about. Below is a strong baseline response you can adapt with your own project examples.
At each house, choose max of two options: rob current house plus best till i-2, or skip current and keep best till i-1. This naturally forms a linear DP recurrence.
Space can be reduced to two rolling variables instead of a full array. That keeps O(n) time and O(1) extra space while preserving correctness.
Discussion
Comments (0)
Share how this question came up in your loop, or add tips for others preparing.
Log in to comment on this question.