Overview
This is best modeled as a finite state machine. On any given day, your portfolio can be in one of three states: Holding Stock (Buy), Just Sold (Sell), or Empty (Cooldown).
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Maximize your profit from stock trading with one restriction: after you sell your stock, you cannot buy stock on the next day (i.e., cooldown 1 day).
This is best modeled as a finite state machine. On any given day, your portfolio can be in one of three states: Holding Stock (Buy), Just Sold (Sell), or Empty (Cooldown).
To enter the `Buy` state today, you either stay in `Buy` from yesterday, or you buy today. But you can ONLY buy today if you were in the `Cooldown` state yesterday.
To enter the `Sell` state today, you either stay in `Sell` from yesterday (doing nothing), or you sell the stock you were holding in the `Buy` state.
The `Cooldown` state is forced. If you sell today, tomorrow you MUST be in cooldown. So tomorrow's `Cooldown` profit is just today's `Sell` profit.