Code
class Solution {
public:
vector<int> findMissingElements(vector<int>& nums) {
int arr[101]{};
int mini = *min_element(nums.begin(), nums.end());
int maxi = *max_element(nums.begin(), nums.end());
for (int i = 0; i < nums.size(); i++) {
arr[nums[i]] = 1;
}
vector<int> missing;
for (int i = mini; i < maxi; i++) {
if (arr[i] == 0) {
missing.push_back(i);
}
}
return missing;
}
}
Logic
- Constraints were:
2 <= nums.length <= 100
1 <= nums[i] <= 100
- Can use a boolean array to toggle elements which are present and which are not
- Tried sorting the thing but couldn't get 100%
- Went with the min_element() and max_element() approach