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

163. House Robber II

MediumDay 47 of 60Dynamic Programming

Same as House Robber, but now the houses stand in a circle: the first and the last house are neighbours. Given nums, the money in each house, return the most you can rob without robbing two adjacent houses.

Example 1
Input: nums = [2,3,2]
Output: 3
Houses 0 and 2 are adjacent in the circle, so the best is to rob house 1.
Example 2
Input: nums = [1,2,3,1]
Output: 4
Rob houses 0 and 2.
Constraints
  • 1 <= nums.length <= 100
  • 0 <= nums[i] <= 1000
Hints
Frequently asked at: Amazon, Microsoft, Google
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