Skip to content

Practice Minimum Cost to Make Arrays Identical

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3424
LeetCode Problem

Minimum Cost to Make Arrays Identical

Problem Statement

Given equally long arrays arr and brr and a cost k, you may split arr into contiguous pieces and reorder those pieces for a fixed cost k per operation. You may also increase or decrease an individual element by a positive integer x for cost x. Return the minimum total cost to make arr equal to brr.

Source: Minimum Cost to Make Arrays Identical on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
arr = [-7,9,5], brr = [7,-2,-5], k = 2
Output
13

# Example 2

Input
arr = [2,1], brr = [2,1], k = 0
Output
0

Constraints

1 <= arr.length == brr.length <= 10^5
0 <= k <= 2 * 10^10
-10^5 <= arr[i] <= 10^5
-10^5 <= brr[i] <= 10^5

Related LeetCode Problems

Practice more problems similar to Minimum Cost to Make Arrays Identical.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.