Medium

Quiz

#453 Minimum Moves to Equal Array Elements

APPROACH

Given an integer array nums of size n, in a single operation you increment exactly n - 1 of the elements by 1. Determine the minimum number of operations needed to make every element in nums equal.

Example 1:

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]

Example 2:

Input: nums = [1,1,1]
Output: 0
1 of 4
1:00

What is the optimal approach for this problem?