Problem
Ask
Submissions

Problem: Best Time to Buy and Sell Stock III

Medium
30 min
Explore how to apply dynamic programming to calculate the maximum profit from at most two stock transactions. This lesson helps you understand essential constraints, develop efficient solutions, and prepare for complex optimization problems commonly seen in coding interviews.

Statement

You are given an array, prices, where prices[i] represents the stock price on day ii.

Determine the maximum profit you can achieve by making at most two transactions. Each transaction consists of a single buy followed by a single sell.

Note: You must complete a sale before initiating a new purchase, and holding multiple stocks at the same time is not allowed.

Constraints:

  • 11 \leq prices.length 105\leq 10^5

  • 00 \leq prices[i] 105\leq 10^5

Problem
Ask
Submissions

Problem: Best Time to Buy and Sell Stock III

Medium
30 min
Explore how to apply dynamic programming to calculate the maximum profit from at most two stock transactions. This lesson helps you understand essential constraints, develop efficient solutions, and prepare for complex optimization problems commonly seen in coding interviews.

Statement

You are given an array, prices, where prices[i] represents the stock price on day ii.

Determine the maximum profit you can achieve by making at most two transactions. Each transaction consists of a single buy followed by a single sell.

Note: You must complete a sale before initiating a new purchase, and holding multiple stocks at the same time is not allowed.

Constraints:

  • 11 \leq prices.length 105\leq 10^5

  • 00 \leq prices[i] 105\leq 10^5