Skip to content

Practice Best Time to Buy and Sell Stock with Cooldown

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#309
LeetCode Problem

Best Time to Buy and Sell Stock with Cooldown

Problem Statement

The array prices gives the stock price on each day. Find the maximum total profit from any number of buy-and-sell transactions, holding at most one share at a time. After selling, you must wait through the next day before buying again. Sell the current share before making another purchase.

Source: Best Time to Buy and Sell Stock with Cooldown on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
prices = [1,2,3,0,2]
Output
3

# Example 2

Input
prices = [1]
Output
0

Constraints

1 <= prices.length <= 5000
0 <= prices[i] <= 1000

Related LeetCode Problems

Practice more problems similar to Best Time to Buy and Sell Stock with Cooldown.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.