Close
Topic list
House Robber
MEDIUM
35 mins
Dynamic Programming
Topics (Covered in this problem)
Problem solved
Skill meter
Dynamic Programming
-
-
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# House Robber

Contributed by
Ratnesh
Medium
0/80
Avg time to solve 35 mins
Success Rate 80 %
Share

## Problem Statement

#### You are given an array/list of non-negative integers 'A' representing the amount of money hidden at each house. Your task is to return the maximum amount of money Mr. X can rob tonight without alerting the police.

##### Example:
``````Input: [1,2,3,1]

Output: 4

Mr. X. can rob the first house and the third house, total money = 1 + 3.
Hence, the total money robbed by Mr. X. is 4.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1 :
``````2
4
4 1 6 10
5
2 5 8 9 1
``````
##### Sample Output 1 :
``````14
14
``````
##### Explanation Of Sample Input 1 :
``````For the first case:

Input: [4,1,6,10]

Output: 4

Mr. X. can rob the first house and the fourth house, total money = 4 + 10.
Hence, the total money robbed by Mr. X. is 14.

For the second case:

Input: [2,5,8,9,1]

Output: 14

Mr. X. can rob the second and fourth houses, total money = 5 + 9.
Hence, the total money robbed by Mr. X. is 14.
``````
##### Sample Input 2 :
``````2
8
6 1 50 1 50 30 6 100
6
55 19 21 13 10 67
``````
##### Sample Output 2 :
``````206
143
``````
Auto
Console