3396: Minimum-Number-of-Operations-to-Make-Elements-in-Array-Distinct
Easy

The answer can be simplified down to:

Code:

class Solution {
public:
    int minOperations(vector<int>& nums, int k) {
        int mp[101] = {0};
        int ans = 0;
        for (int num : nums) {
            if (num < k) return -1;
            if (mp[num] == 0) {
                ++ans;
                mp[num] = 1;
            }
        }
        if (mp[k] == 0) ++ans;
        return ans-1;
    }
};

Complexity: