
The first line contains ‘T’, denoting the number of test cases.
The first line of each test case contains one integer, ‘N’, denoting the number of stores.
The second line of each test case contains an array ‘money’ of ‘N’ space-separated integers, denoting the transaction amount carried out. If money[i] < 0, it means that Alex will pay |money[i]|, and if money[i] > 0, it means Alex will receive money[i] amount.
For each test case, print an integer denoting the maximum amount that Alex can have at any point.
You are not required to print the expected output. It has already been taken care of. Just implement the function.
1 <= T <= 10
1 <= N <= 10^4
-10^5 <= money[i] <= 10^5
Time Limit: 1 sec
For each transaction, ‘i’ find the sum of all transactions ‘j’ such that j <= i. Update the maximum value as needed
The steps are as follows:
One observation is that if we have already calculated the sum of transactions from 0 to i, let’s say p, and then while calculating the sum of transactions from 0 to i + 1, it is just p + money[i + 1]. Hence, we can store the previous sum to calculate the following answer.
The steps are as follows: