Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding
Ninjas X Naukri.com

Problem of the day

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.

Detailed explanation

```
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
```

```
4
10 2 3 11
```

```
21
```

```
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.
```

```
6
5 5 10 100 10 5
```

```
110
```