We’re preparing your current view and syncing the latest data.
You are given an integer array nums. In one operation, you can choose an element that is not the minimum value in the array and reduce it to the next smaller distinct value in the array. Return the minimum number of operations required to make all the elements in the array equal.
An integer array nums of length n.
An integer representing the minimum number of operations to make all elements equal.
1 <= nums.length <= 10^5 1 <= nums[i] <= 10^9
Example 1
Input
[5,1,3]
Output
3
Explanation
Reduce 5 to 3 (1 operation), then reduce 3 to 1 (2 operations total). Total operations = 3.
Example 2
Input
[1,1,2,2,3]
Output
4
Explanation
Reduce two 3's to 2's (2 operations), then reduce three 2's to 1's (2 operations). Total = 4.