House Robber
Advanced
You've been invited to a special adventure where you play the role of the House Robber! Don't worry, you're a good house robber who skips houses to avoid being caught! Your mission is to find the maximum amount of treasure you can collect in a line of houses without robbing two consecutive houses.
The street is represented as a list, where each element is the amount of treasure in a house. Your goal is to write a function, rob_houses, which returns the maximum amount of treasure you can rob without robbing two adjacent houses.
Examples
# Example 1: rob_houses([10, 1, 2, 10, 5]) # You can rob house 1, skip house 2 and 3, then rob house 4 and skip house 5 # Max treasure = 10 + 10 = 20 # Output: 20 # Example 2: rob_houses([2, 7, 9, 3, 1]) # You can rob house 1, skip house 2, rob house 3, skip house 4, rob house 5 # Max treasure = 2 + 9 + 1 = 12 # Output: 12 # Example 3: rob_houses([5, 5, 10, 100, 10, 5]) # You can rob house 1, skip house 2, rob house 4, skip house 5 # Max treasure = 5 + 100 = 105 # Output: 105
Notes
- The input list can have between 0 and 100 items.
- Each house will have an integer treasure value between 0 and 100.
- No input validation is needed.
Inputs
Arg 1:
[10,1,2,10,5]Expected Output
20Actual Output