As reported: Expedia SDE-2 round 2 (2026), second problem: LeetCode 188 Best Time to Buy and Sell Stock IV.
Given an integer k and an array prices (prices[i] is the price on day i), return the maximum profit with at most k transactions. You must sell before buying again.
This is LeetCode 188 — Best Time to Buy and Sell Stock IV.
Example
k = 2, prices = [2,4,1] -> 2
k = 2, prices = [3,2,6,5,0,3] -> 7 (buy 2 sell 6, buy 0 sell 3)
Constraints: 1 ≤ k ≤ 100; 1 ≤ prices.length ≤ 1000; 0 ≤ prices[i] ≤ 1000.
Code runner format: one JSON value per line: k, then prices. Implement maxProfit(k, prices); the harness prints the profit.