Best Time to Trade Stock Many Times
Item prices[i] of the list prices 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 buying again; selling and buying on the same day is fine).
Return the biggest total profit.
Example 1
prices [7,1,5,3,6,4]
returns 7
Buy at 1, sell at 5 (+4); buy at 3, sell at 6 (+3): 7.
Example 2
prices [5,4,3]
returns 0
Prices only fall, so do nothing: 0.
Constraints
1 <= len(prices) <= 300 <= prices[i] <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.