Skip to contentKEEP THE CRAFTTHE SANCTUARY

House Robber

Pick houses to rob so that no two are next to each other and the total is as large as possible.

The problem

Implement Solution.rob(nums). nums[i] is the amount of money in house i along a street. You may rob any set of houses, but never two houses that are next to each other. Return the largest total you can rob. The list can be empty, in which case the answer is 0. There are at most 100 houses and each holds between 0 and 400.

Starter code

class Solution:
    def rob(self, nums):
        pass

Public examples

  1. nums = [2, 7, 9, 3, 1]gives12
  2. nums = [11]gives11
  3. nums = [4, 1, 4]gives8

Solving it in the practice book needs an active paid plan.

Open it in the practice book
One thought at a time.