Practice Best Time to Buy and Sell Stock V
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Given daily prices and k, complete at most k transactions. A normal transaction buys then sells on a later day for the price increase; a short transaction sells then buys back on a later day for the price decrease. Transactions cannot overlap, and a new one cannot start on the day the previous one ends. Return the maximum total profit.
Source: Best Time to Buy and Sell Stock V on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
prices = [1,7,9,8,2], k = 2
14
# Example 2
prices = [12,16,19,19,8,1,19,13,9], k = 3
36
Constraints
Related LeetCode Problems
Practice more problems similar to Best Time to Buy and Sell Stock V.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.