Hi, Everyone

I am struggling in this question from morning. I know there are many solutions out there, but I tried to use my own logic.

I tried every approach with Recursion, Dp but still i got wrong answer. I want someone to please help me with logic.

Recursion- Bottom Up Approach

private static long maximumMonsterMoney(long[] arr, int i) {

if (i >= arr.length) {

return 0;

}

long take = arr[i] + maximumMonsterMoney(arr, i + 2);

long leave = maximumMonsterMoney(arr, i + 1);

return Math.max(take, leave);

}

Top Down Approach

private static void maximumMonsterSum(long[] arr, int start, long sum) {

if (start >= arr.length) {

set.add(sum);

return;

}

sum = sum + arr[start];

maximumMonsterSum(arr, start + 2, sum);

sum = sum - arr[start];

maximumMonsterSum(arr, start + 1, sum);

return;

}

DP- Memoization

private static long maximumMonsterMoneyUsingMemo(long[] arr, int i) {

if (i >= arr.length) {

return 0;

}

if (hm.containsKey(i)) {

return hm.get(i);

}

long take = arr[i] + maximumMonsterMoney(arr, i + 2);

long leave = maximumMonsterMoney(arr, i + 1);

hm.put(i, Math.max(take, leave));

return hm.get(i);

}

DP- Tabulation. I am not being able to solve it.

If there is any issue in this logic please help

I don’t want to cramp those google answers.

Thanks in advance