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

<p>Return <em>the minimum number of moves to make every value in </em><code>nums</code><em> <strong>unique</strong></em>.</p>

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

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,2,2]
<strong>Output:</strong> 1
<strong>Explanation:</strong> After 1 move, the array could be [1, 2, 3].
</pre>

<p><strong class="example">Example 2:</strong></p>

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

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>0 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
</ul>

class Solution:
    def minIncrementForUnique(self, nums: List[int]) -> int:
        # isn't it just the list len - set len? no, because example 2
        # so it isn't how many are dupe, it's how far to move each num to get unique
        # make a dict of each num and count. then walk the nums list and 
        # move any dupe to the closest open slot in the dict - and add to dict
        # or, just sort it and then save any dupe, when hit a gap it's
        # i - dupeindex moves to make it fill the gap
        dupes, moves = [], 0
        heapq.heapify(nums)
        maxnum = max(nums)
        for i in range(maxnum + 1): # walk through the whole space
            if i == nums[0]: # found an input, check for dupes,
                heapq.heappop(nums)
                while nums and nums[0] == i:
                    dupes.append(heapq.heappop(nums))
            else: # have gap, fill with a dupe
                if dupes:
                    dupe = dupes.pop()
                    move = i - dupe
                    print('move', move, 'i', i, 'dupe', dupe)
                    moves += move
        while dupes: # handle any that didn't fit in a gap
            dupe = dupes.pop()
            move = maxnum + 1 - dupe
            print('move no gap ', move, maxnum, 'dupe', dupe)
            moves += move
            maxnum += 1
        return moves
            

27400