One operation replaces any entry of nums with any integer. Return the fewest operations needed to make all entries distinct and make the difference between the maximum and minimum equal to nums.length - 1. The entries can appear in any order.
Example 1:
Input: nums = [7,7,9]
Output: 1Explanation: Replace one 7 with 8 to obtain the distinct values 7, 8, and 9. Their range is 2, as required for three entries.
Example 2:
Input: nums = [2,5,3,4]
Output: 0Explanation: The array already contains each of 2, 3, 4, and 5 once. Their range is 3, and the order of the entries does not matter.
Example 3:
Input: nums = [1]
Output: 0Explanation: A single value is distinct by itself and has range 0, so no operation is needed.
Constraints:
1 <= nums.length <= 1000001 <= nums[i] <= 1000000000