House Robber

Given an array nums where nums[i] is the money in the ith house, return the maximum amount you can rob without robbing two adjacent houses. This is a direct 0/1 decision DP problem on a line.

Input Format

nums = money in each house

Output Format

maximum amount that can be robbed

Constraints

  • 1 <= nums.length <= 10^5; 0 <= nums[i] <= 10^4

Examples

Example 1:

Input:

nums = [1,2,3,1]

Output:

4

Explanation:

Rob houses 1 and 3 for 1 + 3 = 4.

Example 2:

Input:

nums = [2,7,9,3,1]

Output:

12

Explanation:

The best valid plan is 2 + 9 + 1 = 12.

Loading...
House Robber - Dp Knapsack DSA Problem