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.
solution
Incrementing items is logically equivalent to decrementing a single item, which simplifies this problem greatly.
# O(n)
def minMoves(self, nums: List[int]) -> int:
"""
[2,3,3,3]
=> [3,4,4,3] OR [2,3,3,2]
=> [4,5,4,4] OR [2,3,2,2]
=> [5,5,5,5] OR [2,2,2,2]
incrementing n-1 nums is logically equivalent to decrementing one num!
"""
minimum = min(nums)
res = 0
for num in nums:
res += num-minimum
return res