Skip to contentKEEP THE CRAFTTHE SANCTUARY

House Robber II

Rob houses arranged in a circle by solving the straight-street problem twice: once without the first house and once without the last.

The problem

Implement Solution.rob(nums). nums[i] is the money in house i, and the houses stand in a circle, so the first and the last house are next to each other. You may never rob two neighbouring houses. Return the largest total you can rob. There are between 1 and 100 houses, and each holds between 0 and 1,000.

Starter code

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

Public examples

  1. nums = [2, 3, 2]gives3
  2. nums = [2, 7]gives7
  3. nums = [1, 2, 1, 6]gives8

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

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