Skip to interview prep
Apexed

41. House Robber

MediumDynamic programming

nums[i] is the money in house i along a street. You cannot take from two adjacent houses. Return the maximum total you can collect.

Example 1

Input: nums = [2, 7, 9, 3, 1]
Output: 12
Explanation: 2 + 9 + 1

Example 2

Input: nums = [1, 2, 3, 1]
Output: 4

Constraints

  • 1 ≤ nums.length ≤ 100

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 4 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

House Robber — coding interview practice — Apexed