🎉 One-stop destination for all your technical interview Preparation 🎉
Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums.
number > 0
, if its present then we add it in the answer array.class Solution {
public:
vector<int> findDisappearedNumbers(vector<int>& nums) {
int n = nums.size();
for(auto x: nums) {
int curr = abs(x);
nums[curr-1] = - abs(nums[curr-1]);
}
vector<int> ans;
for(int i = 0; i<n;i++){
if(nums[i]>0){
ans.push_back(i+1);
}
}
return ans;
}
};