prices[i] is a stock price on day i. You may buy and sell as many times as you like, but you can hold at most one share at a time (sell before you buy again, on the same day is allowed). Return the maximum total profit.
For [7, 1, 5, 3, 6, 4] the answer is 7 (buy at 1, sell at 5; buy at 3, sell at 6).
Example 1
Input:
max_profit_many([7, 1, 5, 3, 6, 4])
Output:
7
Example 2
Input:
max_profit_many([7, 6, 4, 3, 1])
Output:
0
0 <= len(prices) <= 2000000 <= prices[i] <= 10**9No results yet
Run your code to check it against the examples, or submit to run every test.