Max Loot Without Adjacent Houses
Problem Description
A burglar is planning to rob houses along a street. Each house `i` stores a non-negative integer amount of valuables given by `wealth[i]`. The security system connects adjacent houses, so if two **directly neighbouring** houses are robbed on the same night, the alarm triggers.
Given the array `wealth`, return the **maximum total** that can be looted without robbing any two adjacent houses.
**Example 1:**
```
Input: wealth = [3, 10, 3, 1, 2]
Output: 12
Explanation: Rob houses at indices 1 and 4 → 10 + 2 = 12.
```
**Example 2:**
```
Input: wealth = [6, 7, 6, 7, 6]
Output: 18
Explanation: Rob houses at indices 0, 2, 4 → 6 + 6 + 6 = 18.
```
Constraints
- 1 <= wealth.length <= 10^5
- 0 <= wealth[i] <= 10^4
Follow-up
What if the houses form a **circle** (first and last are also adjacent)? Solve it in O(n) time by running the linear DP twice — once excluding the first house and once excluding the last.
Hints
Try the problem first. If you get stuck, you can reveal hints one at a time.
Solution
Leaderboard
No entries yet for python.
Be the first — submit an accepted solution.