Skip to content
Onsite

House Robber

MediumP1Coding

You are planning to rob houses along a street. nums[i] is the money in house i. Adjacent houses have linked alarms, so you cannot rob two houses next to each other. Return the maximum amount you can rob.

Example 1

Input
nums = [1,2,3,1]
Output
4
Why
Rob houses 0 and 2 for 1 + 3 = 4.

Example 2

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

Example 3

Input
nums = [5]
Output
5

Constraints

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

Hints

Run checks the 3 visible tests, Submit all 11.