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
More Atlassian problems
- Planning ProductionOA · Seen Feb 2025
- K-Means ClusteringOA · Seen Feb 2025
- Minimum Sorted Erasure OperationsOA · Seen Jun 2024
- Count Analogous ArraysOA · Seen Mar 2024
- Get Maximum ScoreOA · Seen Mar 2024
- Better Compression 🦀OA · Seen Mar 2024
- Romanizer 🐡OA · Seen Mar 2024
- Flower Bouquets 💐OA · Seen Mar 2024