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.

  • Create an array 'dp' to store the maximum money that can be stolen up to the i-th house.

  • Itera...read more

Help your peers!
Select
Add answer anonymously...

Bounteous x Accolite Software Engineer interview questions & answers

A Software Engineer was asked 9mo agoQ. Write a function to traverse a binary tree and find the minimum value.
A Software Engineer was asked 10mo agoQ. What is method overriding?
A Software Engineer was asked Q. What is your understanding of OOPS concepts?

Popular interview questions of Software Engineer

A Software Engineer was asked 9mo agoQ1. Write a function to traverse a binary tree and find the minimum value.
A Software Engineer was asked 10mo agoQ2. What is method overriding?
A Software Engineer was asked Q3. What is your understanding of OOPS concepts?

Top HR questions asked in Bounteous x Accolite Software Engineer

A Software Engineer was asked 10mo agoQ1. Describe a difficult situation and how you handled it.
A Software Engineer was asked 11mo agoQ2. Why Accolite over any other company?
A Software Engineer was asked 11mo agoQ3. Where do you see yourself in 5 years?
Bounteous x Accolite Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits