Find the minimum total cost to make an array non-decreasing.
Unlock detailed company stats for this questionUpgrade
Given an integer array nums of length n, in one operation you choose a contiguous segment nums[l..r] (0 <= l <= r < n) and a positive integer x, then add x to every element in that segment at cost x. You may perform any number of operations. Return the minimum total cost to make nums non-decreasing (nums[i] <= nums[i+1] for all 0 <= i < n - 1).
Examples: [3,1,2,4] -> 2 (add 2 to segment [1..2]); [1,2,3] -> 0; [5,3,4,1] -> 5 (add 2 to [1..3], then 3 to [3..3]). Constraints: 1 <= n <= 10^5, 1 <= nums[i] <= 10^9.
Format · Online assessment DSA question.
Community answers
No answers contributed by the community yet.


