prices[i] is a stock's price on day i. You may trade as often as you like, with one rule: you can hold at most one share at a time, so you must sell the share you own before buying another. Selling and then buying again on the same day is allowed. Return the largest total profit you can make.
Buy at 3, sell at 8 (+5). Buy at 2 and sell at 9 (+7). That is 12. Splitting the second trade into 2 → 5 and 5 → 9 earns the same 7.
The price climbs every day: buy on day 0 and sell on day 3.
No day is followed by a higher price, so the best plan is never to buy.
Constraints
1 <= prices.length <= 3 × 10⁴0 <= prices[i] <= 10⁴You can trade as often as you like, so any rise from one day to the next is profit you can collect. A long climb is just the sum of its one-day steps.
12