Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

162. House Robber

MediumDay 47 of 60Dynamic Programming

Houses along a street hold nums[i] money each. You want to rob as much as possible, but robbing two adjacent houses on the same night sets off the alarm. Return the maximum amount you can rob.

Example 1
Input: nums = [1,2,3,1]
Output: 4
Rob houses 0 and 2: 1 + 3 = 4.
Example 2
Input: nums = [2,7,9,3,1]
Output: 12
Rob houses 0, 2 and 4: 2 + 9 + 1 = 12.
Constraints
  • 1 <= nums.length <= 100
  • 0 <= nums[i] <= 400
Hints
Frequently asked at: Amazon, Google, Microsoft, Cisco
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min