<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>

#include <iostream>
#include <unordered_map>
#include <vector>

class Solution {
public:
    int minIncrementForUnique(vector<int>& nums) {
        
  
  unordered_map<int, int> numbers;

  for (const auto num : nums) {
    const auto pos = numbers.find(num);

    if (pos == numbers.end()) {
      numbers[num] = 0;
    }

    numbers[num] += 1;
  }

  vector<int> to_check;
  for (auto rec : numbers) {
    if (1 < rec.second) {
      to_check.push_back(rec.first);
    }
  }

    if (to_check.size() == 0) {
    return 0;
  }

  sort(to_check.begin(), to_check.end());
  int moves = 0;

  int checking = to_check[0] + 1;

  for (auto num : to_check) {
    if (checking < num + 1) {
      checking = num + 1;
    }

    while (numbers[num] > 1) {
      if (numbers.find(checking) == numbers.end()) {
        numbers[num] -= 1;
        numbers[checking] = 1;

        moves += checking - num;
      }

      checking += 1;
    }
  }

  return moves;


    }
};
95956