House Robber Problem Statement

Mr. X is a professional robber with a plan to rob houses arranged in a circular street. Each house has a certain amount of money hidden, separated by a security system that alerts the police if two adjacent houses are robbed on the same night. Your task is to determine the maximum amount of money Mr. X can rob without triggering the alarm.

Explanation:

You are given an array/list of non-negative integers, ARR, representing the amount of money in each house. Find the maximum amount Mr. X can rob without alarming the police, considering the circular arrangement of houses.

Input:

The first line contains an integer 'T', representing the number of test cases. Each test case begins with an integer 'N', the size of ARR, followed by N space-separated integers indicating the amounts of money in respective houses.

Output:

For each test case, print a single integer representing the maximum money that can be robbed, each result on a new line.

Example:

(i) For arr[] = {2, 3, 2}, the output is 3. Mr. X cannot rob houses 1 and 3 because they are adjacent, so he robs house 2.
(ii) For arr[] = {1, 2, 3, 1}, the output is 4. Mr. X robs house 1 and 3.
(iii) For arr[] = {0}, the output is 0. There is nothing to rob.

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 5 x 10^3
  • 1 <= ARR[i] <= 10^9
  • Time limit: 1 sec
Note:
If multiple sets of houses yield the same maximum rob amount, any set is valid. You do not need to handle printing; just implement the function.
AnswerBot
1y

The task is to find the maximum amount of money Mr. X can rob from houses arranged in a circle without alerting the police.

  • The problem can be solved using dynamic programming.

  • Create two arrays to stor...read more

Help your peers!
Select
Add answer anonymously...

Paytm Full Stack Developer interview questions & answers

A Full Stack Developer was asked Q. Sort 0 1 2 Problem Statement Given an integer array arr of size 'N' containing o...read more
A Full Stack Developer was asked Q. What do you know about Paytm?
A Full Stack Developer was asked Q. Cousin Nodes in a Binary Tree Determine if two nodes in a binary tree are cousin...read more

Popular interview questions of Full Stack Developer

A Full Stack Developer was asked Q1. Sort 0 1 2 Problem Statement Given an integer array arr of size 'N' containing o...read more
A Full Stack Developer was asked Q2. What do you know about Paytm?
A Full Stack Developer was asked Q3. Cousin Nodes in a Binary Tree Determine if two nodes in a binary tree are cousin...read more
Paytm Full Stack Developer 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