Back to problems

Best Time to Buy and Sell Stock with Cooldown

Algorithm · Geico · Medium

You are given an array prices where prices[i] is the price of a stock on day i. You can perform as many transactions as you like, but you must observe the following restriction: after selling a share, you cannot buy on the next day. In other words, there is a mandatory one‑day cooldown period between a sale and the next purchase. You may hold at most one share at any moment. Return the maximum profit achievable under these rules. Example 1: Explanation: Buy on day 0 (price…

Loading the rest of the question…