Skip to content
Decoder

House Robber

Medium

Problem

Houses along a street hold nums[i] coins each. You may collect from any houses you like, but never from two neighbours, because adjacent alarms are linked. Return the most coins you can collect.

Example 1

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

Example 2

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

Example 3

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

An empty street gives 0.

Constraints

  • 0 <= nums.length <= 100
  • 0 <= nums[i] <= 400

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.