You are a robber planning to rob houses arranged in a line, where each house holds a given amount of money. You cannot rob two adjacent houses (doing so triggers an alarm). Return the maximum amount of money you can rob.
nums = [1,2,3,1]4nums = [2,7,9,3,1]12Solve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.
Solve on FeatCode →Break a problem into overlapping subproblems along a single dimension — like "the answer up to index i" — solve each one once, and reuse the result instead of recomputing it.
Read the full 1-D Dynamic Programming guide →
Original problem on LeetCode ↗