← All solutions
November 1Medium

Minimum moves to equal array elements

  • Array
  • Math

Problem

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

class Solution:
    def minMoves(self, nums: list[int]) -> int:
        return sum(nums) - min(nums)*len(nums)