leetle

Daily challenge for 2025-03-13

72. Best Time to Buy and Sell Stock with Cooldown

Write solve to maximize profit with a 1-day cooldown period after selling. You cannot engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again). The input is an array of prices where prices[i] is the price of a given stock on the ith day.

Example:
Input: [1,2,3,0,2]
Output: 3
Explanation: Buy on day 1 (price = 1), sell on day 2 (price = 2), cooldown on day 3, buy on day 4 (price = 0), and sell on day 5 (price = 2). Total profit = (2-1) + (2-0) = 3.

Run this challenge interactively in Python or JavaScript when the app loads.