Problem of the day
Let's say, 'PRICES' = [7, 1, 5, 4, 3, 6]
Purchase stock on day two, where the price is one, and sell it on day three, where the price is five, profit = 5 - 1 = 4.
Purchase stock on day five, where the price is three, and sell it on day six, where the price is six, profit = 6 - 3 = 3.
Total Profit is 4+3 = 7. Hence we return 7.
First-line contains 'T', denoting the number of Test cases.
For each Test case:
The first line contains an integer 'N' denoting the size of the array 'PRICES'.
The second line includes 'N' integers denoting the elements of the array 'PRICES'.
Return the maximum profit you can achieve.
You don't need to print anything. Just implement the given function.
1 <= 'T' <= 10
1 <= 'N' <= 10^5
1<= 'PRICES[i]' <= 10^9, 0 <= i <= 'N-1'
Time Limit: 1 sec
2
6
7 1 5 4 3 6
6
100 160 220 40 535 695
7
775
For test case 1:
'PRICES' = [7, 1, 5, 4, 3, 6]
Purchase stock on day two, where the price is one, and sell it on day three, where the price is five, profit = 5 - 1 = 4.
Purchase stock on day five, where the price is three, and sell it on day six, where the price is six, profit = 6 - 3 = 3.
Total Profit is 4+3 = 7. Hence we return 7.
For test case 2:
'PRICES' = [100, 160, 220, 40, 535, 695]
Purchase stock on day one, where the price is 100, and sell it on day three, where the price is 220, profit = 220 - 100 = 120.
Purchase stock on day four, where the price is 40, and sell it on day six, where the price is 695, profit = 695 - 40 = 655.
Total Profit is 120+655 = 775. Hence we return 775.
2
5
5 4 3 2 1
1
13
0
0