The recurrence: dp[i] = max(nums[i] + dp[i-], dp[i-]) Base cases: - dp[] = nums[] (only one house, rob it) - dp[] = max(nums[], nums[]) (two houses, rob the richer one) Build up from these base cases. Like Climbing Stairs, you only need the previous two values, so you can optimize to space.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/maang-interview-prep/dynamic-programming/house-robber-solution
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████████████████████████████████████████████████████████████████████████████████████████