πŸ“ Problem Details

πŸ’­What Were My Initial Thoughts?

sorting the array could be useful
using a hashmap could be a way to avoid the need to sort

πŸ€”What Did I Struggle With?

~

πŸ’‘ Explanation of Solution

- initialize and populate an unordered set with all values in nums
- interate through the array, starting with an index i = 1
- check if i exists in the set, if it doesnt then push i into a results vector
- return result

βŒ› Complexity Analysis

Time Complexity: O(n)
Space Complexity: O(n)

πŸ’» Implementation of Solution

class Solution {
 
public:
Β  Β  vector<int> findDisappearedNumbers(vector<int>& nums) {
Β  Β  Β  Β  unordered_set<int> set(nums.begin(), nums.end());
Β  Β  Β  Β  vector<int> result;
 
Β  Β  Β  Β  for(int i=1; i <= nums.size(); i++) {
Β  Β  Β  Β  Β  Β  if(set.find(i) == set.end()) {
Β  Β  Β  Β  Β  Β  Β  Β  result.push_back(i);
Β  Β  Β  Β  Β  Β  }
Β  Β  Β  Β  }
Β  Β  Β  Β  return result;
Β  Β  }
};