# House Robber - Dynamic Programming / Sequence

``````if len(nums) < 2:
return max(nums)
``````

Shouldn’t this be < than 3. If there is only 1 house, no point in finding the max. If there are two hoses, the thief can choose whichever house has more to offer.

This test case:
2 12 9 3 4
returns 16.

This code returns the correct answer:
def rob(nums: List[int]) → int:
odd, even = 0, nums[0]
for i in range(1, len(nums)):
if i % 2 == 0:
even += nums[i]
else:
odd += nums[i]
return max(odd, even)

Both @Fixer and @am are right, one can rob house 12 and 4, totaling 16. The approach proposed returns 16 indeed

AlgoMonster is severely missing the test cases in general.

Line 6 for JS answer is incorrect. The nums array should be spread into Math.max since it takes numbers as input not an array.

where is the java solution for this problem?

Only @am is correct. Fixer used his own code and thought his solution is correct, but it isn’t.

Yeah, this is confusing. I think they meant to do ‘n < 3’ instead of ‘n < 2’.

I think THIS post here (https://leetcode.com/problems/house-robber/discuss/156523/From-good-to-great.-How-to-approach-most-of-DP-problems. ) should be the bases for DP problems approach (and implicitly how YOU should explain it). Currently your introductory chapter on this VERY important topic is ambiguous and… not here nor there (you make it sound like it’s a type of problem you could tackle only if you’re “talented / gifted” enough)

Hey, thanks for the message. I agree the DP section is a bit weak. We are in the process of reworking it. That being said, I’m not sure where we would have made you think ‘it’s a type of problem you could tackle only if you’re “talented / gifted” enough’. I think what we meant was DP is lower ROI as mentioned in the very beginning and is not worth spending too much time on (unless you are going for google which only has 2 coding interviews starting May 2022).

I may have misspoken on the “gifted” part. I think the fact that I am actually going for Google is why I am currently seeing a lot of DP problems (at least on leetcode) from them and AlgoMonster seems to not really treat this chapter as in depth as the others.

One other remark I have: the templates are really good and I have to commend you on those. On the other hand, there are some instances where in solving some problem the solution does not actually respect the corresponding template and somewhat complicates things more.

Also, I think I identified at least 3 coding styles in your solutions across multiple chapters: I have to say it’s a bit distracting and disruptive on the learning flow.