rates[i] is its price on day i. A trade is buying the coin and selling it later. You can hold at most one coin at a time, so a new purchase is only possible after the previous coin is sold (the same day is fine).
You may make at most max_trades trades. Return the largest total profit; if no profit is possible, return 0.max_trades=2, rates=[5, 1, 4, 2, 8, 3, 6] → 10
Buy at 1, sell at 8 (+7); buy at 3, sell at 6 (+3), 10 in total. Trading 1 → 4 and 2 → 8 instead would give only 9.
max_trades=1, rates=[3, 7, 2, 6] → 4
The best single trade is 3 → 7 or 2 → 6, both earning 4.
max_trades=4, rates=[10] → 0
max_trades=2, rates=[5, 1, 4, 2, 8, 3, 6]
10
Run checks the first 3 tests in your browser. Submit checks all 98 tests on the server, hidden ones included.