Paths Subjects Questions Quizzes Pricing Search
Intermediate Open Pro

Neighborhood Burglary

You are a professional robber planning to rob houses along a street, given as an integer array nums where nums[i] is the amount of money in house i. Adjacent houses have connected security systems, so robbing two adjacent houses on the same night automatically triggers the alarm. Return the maximum amount of money you can rob without robbing two adjacent houses.

Example 1

Input: nums = [1, 2, 3, 1]
Output: 4
Explanation: Rob house 0 (money = 1) and house 2 (money = 3).
Total = 1 + 3 = 4.

Example 2

Input: nums = [2, 7, 9, 3, 1]
Output: 12
Explanation: Rob house 0 (2), house 2 (9), and house 4 (1).
Total = 2 + 9 + 1 = 12.

Constraints

  • 1 <= nums.length <= 100
  • 0 <= nums[i] <= 400

Share this question

← Back to Dynamic Programming practice

We use cookies for product analytics to improve OmniAtlas. See our Privacy Policy.