> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Minimum Moves to Equal Array Elements

> Tested Python solution for LeetCode 453 with 26 pytest cases. Generate a practice environment with lcpy.

LeetCode 453, [Medium](/catalog/medium). Topics: [Array](/catalog/topics/array), [Math](/catalog/topics/math). [View on LeetCode](https://leetcode.com/problems/minimum-moves-to-equal-array-elements/description/).

Generate this problem as a practice environment: tested reference solution, 26 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 453   # by problem number
lcpy gen -s minimum_moves_to_equal_array_elements   # by problem name
```

## 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`.

### Examples

```
Input: nums = [1,2,3]
Output: 3
Explanation: Only three moves are needed (remember each move increments two elements):
[1,2,3]  =>  [2,3,3]  =>  [3,4,3]  =>  [4,4,4]
```

```
Input: nums = [1,1,1]
Output: 0
```

### 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.

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_moves_to_equal_array_elements/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_moves_to_equal_array_elements/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(n)
    # Space: O(1)
    def min_moves(self, nums: list[int]) -> int:
        # Each move raises n - 1 elements by 1, so the minimum never falls behind.
        # Equivalently, every element must climb to the maximum: one move can be
        # seen as lowering a single element by 1, giving sum(nums) - n * min(nums).
        return sum(nums) - min(nums) * len(nums)
```

## Complexity

| Time | Space |
| - | - |
| O(n) | O(1) |

## Tags


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.