You are given a list of houses on a street, with the numeric value representing the amount of money stashed away in each house.
Write a method to find the maximum amount of money you can steal. You cannot steal from any two adjacent houses, otherwise you will be caught! Use Dynamic Programming!
robbery([60, 50, 20, 32, 20, 50])→
robbery([40, 25, 25, 30])→
I would like to ask for a review of the following solution.
def robbery(amounts): amounts = iter(amounts) prev, total = 0, next(amounts, 0) for x in amounts: prev, total = total, max(total, prev + x) return total
Here's my code on Gist: https://gist.github.com/Jeffchiucp/6dbd481ce4bc208e6da68bc8e920bf3f