A trading simulator shows daily prices in prices. You may make as many trades as you like, but you can hold at most one share at a time, and after selling you must rest for one full day before buying again.
Write profitWithRest(prices) that returns the largest total profit.
Input: prices = [2,3,4,1,3] Output: 3
Buy at 2, sell at 3, rest on the day priced 4, buy at 1, sell at 3: 1 + 2.
Input: prices = [5] Output: 0
One day leaves no time to trade.
1 <= prices.length <= 50000 <= prices[i] <= 1000Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #553 Trades With a Rest Day. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.