

Input: [1,2,3,1]
Output: 4
Mr. X. can rob the first house and the third house, total money = 1 + 3.
Hence, the total money robbed by Mr. X. is 4.
The first line will contain the integer 'T', denoting the number of test cases.
The first line of each test case contains one integer 'N' denoting the size of array 'A'.
The second line of each test case contains 'N' single space-separated integers, elements of the array 'A'.
For each test case, Return the maximum amount of money Mr. X can rob tonight without alerting the police.
You don't need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 50
1 <= N <= 10^5
0 <= A[i] <= 10ٰ^9
Time Limit: 1 sec
In this approach, we are trying out all possibilities.
At every 'i'th house robber has two options
If he is robbing the 'i'th house, he can have the money hidden at 'i'th house, and the money robbed till 'i-2'th house, let's say it 'X'.
If he is not robbing the 'i'th house, he can have the money robbed till 'i-1'th house, let's say it 'Y'.
So, the maximum money he robs till 'i'th house is max( X, Y ).
We can see that we only need the answer to the 'i-1'th and 'i-2'th index to calculate the answer for the 'i'th index.
Hence, we can maintain two variables, 'lastAns' and 'secondLastAns', to store the answer till the 'i-1'th and the 'i-2'th index.
The answer for the current index can be the maximum of the 'secondLastAns' + 'A[i]' and 'lastAnswer'.
Before moving to the next index, 'secondLastAnswer' will be equal to 'lastAnswer', and 'lastAnswer' will be equal to 'curAnswer'.
Finally, return the answer on the 'N-1'th index. (0-based indexing).