You are given an array arr where each element represents the cost of a stock on a particular day. Your task is to determine the maximum possible profit you can achieve by buying and selling the stock multiple times.
Note:
Example 1
Input: arr[] = [10, 22, 5, 75, 65, 80]
Output: 97
Explanation: Buy the stock on day 0 and sell it on day 1 => 22 - 10 = 12. Buy the stock on day 2 and sell it on day 3 => 75 - 5 = 70. Buy the stock on day 4 and sell it on day 5 => 80 - 65 = 15. Maximum Profit = 12 + 70 + 15 = 97
Example 2
Input: arr[] = [90, 80, 70, 60, 50]
Output: 0
Explanation: No transactions can be made as the stock prices are continuously falling. Therefore, the maximum profit is 0.
Sign in to write, run, and submit your solution against the full test suite.