Concept Flow - Buy and Sell Stocks All Variants
Start
Choose Variant
Variant 1: One Transaction
Track min price, max profit
Update profit if price - min_price > profit
End
Variant 2: Multiple Transactions
Sum all positive price differences
End
Variant 3: At Most Two Transactions
Use DP arrays: left_profit, right_profit
Combine max profits from left and right
End
Variant 4: At Most K Transactions
Use DP table: dp[k
Calculate max profit with k transactions
End
The flow starts by selecting the variant of the stock buy-sell problem, then follows the specific steps to calculate max profit according to that variant.
