You are given an integer array nums. In one move, you can pick an index i where 0 &lt;= i &lt; nums.length and increment nums[i] by 1.

Return the minimum number of moves to make every value in nums unique.

The test cases are generated so that the answer fits in a 32-bit integer.

&nbsp;
Example 1:

Input: nums = [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].


Example 2:

Input: nums = [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 105
	0 &lt;= nums[i] &lt;= 105


class Solution:
    def minIncrementForUnique(self, nums: List[int]) -> int:
        nums.sort()
        c=0
        i=1
        num=[]
        
        while i<len(nums):
            if nums[i]<=nums[i-1]:
                a=nums[i-1]+1
                c+=(a-nums[i])
                nums[i]=a
            i+=1
        return c
    
class Solution {
    public int minIncrementForUnique(int[] nums) {
        
        //Approach - 1 : Using a Count array
        
        // TC : O(N)
        // SC : O(N)
        
        int max = 0;
        for(int i : nums)
            max = Math.max(max, i);
        
        int count[] = new int[nums.length + max];
		
        for(int c : nums)
            count[c]++;
			
        int answer = 0, choosen = 0;
		int len = count.length;
		
        for(int i = 0; i< len; i++)
        {
            if(count[i] >= 2)
            {
                choosen += count[i] - 1;
                answer -= i * (count[i] - 1);
            }
            else if(choosen > 0 && count[i] == 0)
            {
                answer += i;
                choosen--;
            }
        }
		
        return answer;
        
        
        //Approach - 2:
        
        // TC : O(nlogn)
        // SC : O(1)
        
        Arrays.sort(nums);
        int answer = 0;
        for(int i=1; i<nums.length; i++)
        {
            if(nums[i-1] >= nums[i]){
                answer += nums[i-1]- nums[i] +1;
                nums[i] = nums[i-1] + 1; 
            }
        }
        return answer;
    }
}
class Solution {
public:
    int minIncrementForUnique(vector<int>& nums) {
        int minElePossible=0,ans=0;
        sort(nums.begin(),nums.end());
        for(int i=0;i<nums.size();i++){
            if(nums[i]<minElePossible){
                ans+=minElePossible-nums[i];
                nums[i]+=minElePossible-nums[i];
            }
            minElePossible=nums[i]+1;
        }
        return ans;
    }
};
var minIncrementForUnique = function(nums) {
  let ans = 0, arr = nums.sort((a, b) => a - b);

  for (let i = 0; i < arr.length; i++) {
    if (arr[i] === arr[i + 1]) {
      arr[i + 1]++;
      ans++;
    }
    else if (arr[i] > arr[i + 1]) {
      if(arr[i] - arr[i - 1] === 1){
        ans += arr[i] - arr[i + 1] + 1
        arr[i + 1] += arr[i] - arr[i + 1] + 1;
      }
    }
  }

  return ans;
};
Minimum Increment to Make Array Unique