Skip to content
Decoder

House Robber II

Medium

Problem

This time the houses stand in a circle, so the first and last houses are neighbours too. As before, nums[i] is the number of coins in house i, and you may never collect from two adjacent houses. Return the most coins you can collect.

Example 1

Input
nums = [2, 3, 2]
Output
3
Why
houses 0 and 2 touch, so take house 1

Example 2

Input
nums = [1, 2, 3, 1]
Output
4
Why
houses 0 and 2

Example 3

Input
nums = [1, 2, 3]
Output
3

Constraints

  • 1 <= nums.length <= 100
  • 0 <= nums[i] <= 1000

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.