Tap here to switch tabs
Problem
Submissions

Problem: Best Time to Buy and Sell Stock IV

Try to solve the Best Time to Buy and Sell Stock IV problem.

Statement

Given an integer array prices, where prices[i] represents the price of a stock on the i^{th} day, and an integer k, determine the maximum profit achievable by completing at most k transactions.

A transaction consists of buying the stock on one day and selling it on a later day.

Note: You cannot hold multiple stocks simultaneously. You must sell the current stock before buying again.

Constraints:

  • 1≤1 \leq k ≤102\leq 10^2

  • 1≤1 \leq prices.length ≤103\leq 10^3

  • 0≤0 \leq prices[i] ≤103\leq 10^3

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Best Time to Buy and Sell Stock IV

Try to solve the Best Time to Buy and Sell Stock IV problem.

Statement

Given an integer array prices, where prices[i] represents the price of a stock on the i^{th} day, and an integer k, determine the maximum profit achievable by completing at most k transactions.

A transaction consists of buying the stock on one day and selling it on a later day.

Note: You cannot hold multiple stocks simultaneously. You must sell the current stock before buying again.

Constraints:

  • 1≤1 \leq k ≤102\leq 10^2

  • 1≤1 \leq prices.length ≤103\leq 10^3

  • 0≤0 \leq prices[i] ≤103\leq 10^3