House Robber on a Line

Given an array nums where nums[i] is money in the ith house, return the maximum amount you can rob without robbing adjacent houses. Pattern focus: Take Or Skip DP. At each index, decide whether to take the current house or skip it.

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^9

Examples

Example 1:

Input:

nums = [1,2,3,1]

Output:

4

Explanation:

Rob houses 1 and 3.

Example 2:

Input:

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

Output:

12

Explanation:

Rob houses 1, 3, and 5.

Loading...
House Robber on a Line - Dp 1d DSA Problem