FreeCareerPath
Build the PrimitiveMedium

House Robber

Write `rob(nums)` returning the largest sum obtainable from a list with no two chosen elements adjacent. rob([2,7,9,3,1]) -> 12 (2 + 9 + 1) At each house you either take it and add the best up to two houses back, or skip it and keep the best up to the previous one. Two variables carry everything you need — no array required.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "House Robber" are saved to your account — logging in takes a few seconds.

House Robber — FreeCareerPath