Given an integer array nums of size n, return the minimum number of moves required to make all array elements equal. In one move, you can increment n - 1 elements of the array by 1.
Given an integer array nums of size n, return the minimum number of moves required to make all array elements equal. In one move, you can increment n - 1 elements of the array by 1.
Example 1:
Input: {"nums":[1,2,3]}
Output: 3
Constraints:
n=nums.length
1≤n≤105
−109≤nums[i]≤109
The answer is guaranteed to fit in a 32-bit integer.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[1,2,3]}
One move adds 1 to 2 of the 3 elements. What is the fewest moves that makes all 3 equal?
- - minimum■ height above the minimum = moves needed