


It is possible for Mr. X to rob the same amount of money by looting two different sets of houses. Just print the maximum possible robbed amount, irrespective of sets of houses robbed.
(i) Given the input array arr[] = {2, 3, 2} the output will be 3 because Mr X cannot rob house 1 (money = 2) and then rob house 3 (money = 2), because they are adjacent houses. So, he’ll rob only house 2 (money = 3)
(ii) Given the input array arr[] = {1, 2, 3, 1} the output will be 4 because Mr X rob house 1 (money = 1) and then rob house 3 (money = 3).
(iii) Given the input array arr[] = {0} the output will be 0 because Mr. X has got nothing to rob.
The first line of input contains an integer 'T' representing the number of the test case. Then the test case follows.
The first line of each test case contains an integer, ‘N’ representing the size of the first array/list.
The second line of each test case contains 'N' single space-separated integers representing the array/list elements.
For each test case, print a single line containing a single integer denoting the maximum money that can be robbed in a separate line.
The output of each test case will be printed in a separate line.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 5 x 10 ^ 3
1 <= ARR[i] <= 10 ^ 9
Time limit: 1 sec.
The main point is that you can't rob both the first and the last houses.
Therefore, the core idea is to apply dynamic programming. Two cases are considered here:
The dynamic programming algorithm that must be applied considering two arrays, given array ARR and new array DP to store value till the ith house is: