Loot Houses Problem Statement
A thief is planning to steal from several houses along a street. Each house has a certain amount of money stashed. However, the thief cannot loot two adjacent houses. Determine the maximum amount of money the thief can steal without looting two consecutive houses.
Input:
The first line contains an integer 'N', representing the number of houses.
The second line contains 'N' space-separated integers, representing the money available in each house.
Output:
The maximum amount of money the thief can loot without looting two consecutive houses.
Example:
Input:
N = 4
values = [6, 7, 1, 30]
Output:
36
Explanation:
The thief can loot houses 1 and 4 (0-indexed), obtaining 6 + 30 = 36.
Constraints:
0 <= N <= 10^5
0 <= A[i] <= 10^4
Note that 'A[i]' represents the money present in the i-th house, and you don’t need to print anything, just implement the function.

AnswerBot
4mo
Determine the maximum amount of money a thief can steal from houses without looting two consecutive houses.
Use dynamic programming to keep track of the maximum money that can be stolen up to each hous...read more
Help your peers!
Add answer anonymously...
PubMatic SDE-2 interview questions & answers
A SDE-2 was asked Q. Convert Binary Tree to Mirror Tree Convert a given binary tree into its mirror t...read more
A SDE-2 was asked Q. Loot Houses Problem Statement A thief is planning to steal from several houses a...read more
A SDE-2 was asked Q. Trailing Zeros in Factorial Problem Find the number of trailing zeroes in the fa...read more
Popular interview questions of SDE-2
A SDE-2 was asked Q1. Convert Binary Tree to Mirror Tree Convert a given binary tree into its mirror t...read more
A SDE-2 was asked Q2. Loot Houses Problem Statement A thief is planning to steal from several houses a...read more
A SDE-2 was asked Q3. Trailing Zeros in Factorial Problem Find the number of trailing zeroes in the fa...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

