Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

House Robber

Medium
dynamic-programmingarray

A robber walks a street of houses with cash amounts nums, but robbing two adjacent houses trips the alarm. Return the maximum loot.

Input: one line of space-separated non-negative integers. Output: the maximum amount.

Example 1
Input:
1 2 3 1
Output:
4

Rob houses 0 and 2.

Example 2
Input:
2 7 9 3 1
Output:
12

Rob 2 + 9 + 1.

Constraints

  • 1 ≤ nums.length ≤ 100
  • 0 ≤ nums[i] ≤ 400
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.