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;
[num] = 1;
mp}
}
if (mp[k] == 0) ++ans;
return ans-1;
}
};