Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Amazon/Q15-Stickler Thief
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

Stickler the thief wants to loot money from a society having n houses in a single line.
He is a weird person and follows a certain rule when looting the houses.
According to the rule, he will never loot two consecutive houses.
At the same time, he wants to maximize the amount he loots.
The thief knows which house has what amount of money but is unable to
come up with an optimal looting strategy.
He asks for your help to find the maximum money he can get if he strictly follows the rule.
ith house has a[i] amount of money present in it.


Example 1:
Input:
n = 5
a[] = {6,5,5,7,4}
Output:
15
Explanation:
Maximum amount he can get by looting 1st, 3rd and 5th house. Which is 6+5+4=15.

Example 2:
Input:
n = 3
a[] = {1,5,3}
Output:
5
Explanation:
Loot only 2nd house and get maximum amount of 5.

Expected Time Complexity:O(N).
Expected Space Complexity:O(1).

Constraints:
1 ≤ n ≤ 105
1 ≤ a[i] ≤ 104