Skip to content

Practice Minimum Cost to Make Array Equal

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

Hard#2448
LeetCode Problem

Minimum Cost to Make Array Equal

Problem Statement

Changing nums[i] by +1 or -1 costs cost[i] each time. Apply these changes any number of times to make every nums entry equal. Return the minimum total cost.

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

Examples

# Example 1

Input
nums = [1,3,5,2], cost = [2,3,1,14]
Output
8

# Example 2

Input
nums = [2,2,2,2,2], cost = [4,2,8,1,3]
Output
0

Constraints

n == nums.length == cost.length
1 <= n <= 10^5
1 <= nums[i], cost[i] <= 10^6
Test cases are generated in a way that the output doesn't exceed 2^53 - 1

Related LeetCode Problems

Practice more problems similar to Minimum Cost to Make Array Equal.

Review your practice with PhantomCodeAI

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