Problem title
Difficulty
Avg time to solve

Pair Sum
Easy
15 mins
House Robber
Moderate
26 mins
Find All Triplets With Zero Sum
Moderate
30 mins
Find power of a number
Easy
15 mins
Longest Sub-string With K Distinct Characters
Easy
15 mins
Factorial Of Large Number
Moderate
30 mins
Count Subarrays with Given XOR
Moderate
15 mins
Cooking Ninjas
Moderate
25 mins
Set Bits
Easy
--
Find K’th Character of Decrypted String
Moderate
33 mins
28

# House Robber

Difficulty: MEDIUM
Contributed By
Avg. time to solve
26 min

Problem Statement

#### A thief wants to loot houses. He knows the amount of money in each house. He cannot loot two consecutive houses. Find the maximum amount of money he can loot.

##### Input Format :
``````The first line of input contains a single integer 'N' denoting the total number of houses.

The second line of input contains 'N' single space-separated integers, denoting the amount of money in every 'i-th' house.
``````
##### Output Format :
``````The only line of output will print the maximum amount of loot that is possible.
``````
##### Note :
``````You don’t need to print anything, it has already been taken care of. Just implement the given function.
``````
##### Constraints :
``````0 <= 'N' <= 10^5
0 <= 'A[i]' <= 10^4

Where 'A[i]' represents the money present in the 'i-th' house.

Time limit: 1 sec
``````
##### Sample Input 1:
``````4
10 2 3 11
``````
##### Sample Output 1:
``````21
``````
##### Explanation of Sample Input 1:
``````Since the thief cant loot two consecutive houses, the ways in which he may loot are:

1. [10, 3]: a total loot of 13
2. [10, 11]: a total loot of 21
3. [2, 11]: a total loot of 13
4. [10]: a total loot of 10
5. [2]: a total loot of 2
6. [3]: a total loot of 3
7. [11]: a total loot of 11

We can't neglect the option to loot just either of the houses if it yields the maximum loot.

From all the possible seven ways, the second option yields the maximum loot amount and hence the answer.
``````
##### Sample Input 2:
``````6
5 5 10 100 10 5
``````
##### Sample Output 2 :
``````110
``````
Console