JuniorArrayMath

Minimum Moves to Equal Array Elements III

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.

Example 1
Inputnums = [2,1,3]
Output3
Increasing 2 once and 1 twice makes every element equal to 3, for a minimum total of 3 moves.
Example 2
Inputnums = [4,4,5]
Output2
Increasing both 4s once makes every element equal to 5, for a minimum total of 2 moves.

Constraints

  • 1 <= nums.length <= 100
  • 1 <= nums[i] <= 100

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate