1120. House Robber I

EasyDynamic Programming1D DP

Given an array nums where nums[i] is the money in house i, you cannot rob two adjacent houses. Return the maximum amount you can rob. The input is JSON {nums}.

Input: JSON {nums}.

Output: Integer — the maximum robbable amount.

Examples

Example 1
Input: {"nums":[1,2,3,1]}
Output: 4
Explanation: Rob houses 0 and 2.
Example 2
Input: {"nums":[2,7,9,3,1]}
Output: 12
Explanation: Rob houses 0, 2, and 4.
Example 3
Input: {"nums":[]}
Output: 0
Explanation: No houses.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →