Skip to main content
Back to problems
#3736
Easy Algorithms

Minimum moves to equal array elements iii

Array Math
81.3% acceptance
Feb 24, 2026
35
2
You are given an integer array nums. In one move, you may increase the value of any single element nums[i] by 1. Return the minimum total number of moves required so that all elements in nums become equal.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn min_moves(nums: Vec<i32>) -> i32 {
    let max_val = *nums.iter().max().unwrap();
    nums.iter().map(|&x| max_val - x).sum()
  }
}