Problem 2606 · Medium

Find the Substring With Maximum Cost

Kadane-style DP: the best substring ending at each position is max(0, previous + value), and the answer is the best of these.

Open the interactive visualisation