Great answer with clear explanation. It's all clear and obvious once the solution is understood. But, where do I learn how to define the states? If we see this problem But and sell stock IV which looks similar, but the state definition there is different.
Best Time to Buy and Sell Stock with Cooldown