Problem 2263 · Hard

Make Array Non-decreasing or Non-increasing

Run a DP over the original values as targets, once for each orientation, and keep the cheaper cost.

Open the interactive visualisation