Minimum Moves to Equal Array Elements Problem
Minimum Moves to Equal Array Elements Problem — ExecCode Easy DSA Practice
Solve the Minimum Moves to Equal Array Elements problem on ExecCode. Free online easy DSA practice in Math. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given an integer array nums of size n, return the minimum number of moves required to make all array elements equal. Your task is to in one move, you can increment n - 1 elements of the array by 1. Return the required answer exactly as shown in the examples.
Examples
Input {"nums": [1, 2, 3]}; Output 3. Input {"nums": [1, 1, 1]}; Output 0. Input {"nums": [1, 5, 9]}; Output 12
Constraints
n == nums.length 1 <= nums.length <= 10^5 -10^9 <= nums[i] <= 10^9 The answer is guaranteed to fit in a 32-bit integer.
Practice Minimum Moves to Equal Array Elements free on ExecCode. Browse DSA problems, topic map, and placement guides.