Problem · Array
Minimum Total Cost to Equalize an Array
Learn this problemProblem statement
An operation chooses a prefix and adds any integer x to every value in that prefix at cost |x|. Return the minimum total cost needed to make every array element equal.
Function
findMinimumCost(arr: int[]) → longExamples
Example 1
arr = [1,2,1,5]return = 6The neighboring differences require costs 1, 1, and 4, for a total of 6.
Constraints
1 <= arr.length <= 200000-10^9 <= arr[i] <= 10^9