188. Best Time to Buy and Sell Stock IV
Problem Statement
You are given an integer array prices
where prices[i]
is the price of a given stock on the ith
day, and an integer k
.
Find the maximum profit you can achieve. You may complete at most k
transactions: i.e. you may buy at most k
times and sell at most k
times.
Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).
Example 1:
Example 2:
Constraints:
1 <= k <= 100
1 <= prices.length <= 1000
0 <= prices[i] <= 1000
Intuition
Links
https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/description/
Video Links
https://www.youtube.com/watch?v=IV1dHbk5CDc&ab_channel=takeUforward
Approach 1:
C++
Approach 2:
C++
Approach 3:
C++
Approach 4:
C++
Similar Problems
Last updated