Problem 3962 · Medium

Maximum Subarray Sum After at Most K Swaps

Swap up to k pairs of positions, then pick a contiguous block. For each block, trade its weakest values for the strongest outside values while the trade still gains.

Open the interactive visualisation