Practice Minimum Cost to Equalize Array
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Given nums, cost1, and cost2, you may increase one element by 1 for cost1, or increase two elements at distinct indices by 1 each for cost2. Perform either operation any number of times. Find the minimum total cost to make all elements equal, then return that minimum cost modulo 10^9 + 7.
Source: Minimum Cost to Equalize Array on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [4,1], cost1 = 5, cost2 = 2
Output
15
# Example 2
Input
nums = [2,3,3,3,5], cost1 = 2, cost2 = 1
Output
6
# Example 3
Input
nums = [3,5,3], cost1 = 1, cost2 = 3
Output
4
Constraints
1 <= nums.length <= 10^5
1 <= nums[i] <= 10^6
1 <= cost1 <= 10^6
1 <= cost2 <= 10^6
Related LeetCode Problems
Practice more problems similar to Minimum Cost to Equalize Array.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.