From 87d3dee49113092c7b079fe3aa75cedd847b894a Mon Sep 17 00:00:00 2001 From: Abiral jain <134861989+Abiral-2724@users.noreply.github.com> Date: Sun, 15 Oct 2023 19:01:08 +0530 Subject: [PATCH] Create Q15-Stickler Thief --- Amazon/Q15-Stickler Thief | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Amazon/Q15-Stickler Thief diff --git a/Amazon/Q15-Stickler Thief b/Amazon/Q15-Stickler Thief new file mode 100644 index 0000000..ce35a77 --- /dev/null +++ b/Amazon/Q15-Stickler Thief @@ -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 +