Dsa
Dynamic Programming
Easy
Non-Consecutive Sum
You are given an array of integers representing amounts of money. Your goal is to determine the maximum sum of money you can rob, given the constraint that you cannot rob two consecutive amounts (houses).
Input:
- The first line contains an integer n (1 ≤ n ≤ 1000), the number of houses.
- The second line contains n space-separated integers representing the money in each house.
Output:
- A single integer representing the maximum amount of money that can be robbed without robbing two consecutive houses.
Example:
Input:
5
2 7 9 3 1
Output:
12
Explanation:
Rob houses with amounts 2, 9, and 1; totaling the maximum of 12.
Key concepts
dynamic_programmingarrayoptimization
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now