Source: https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/

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.

/**
* @param {number[]} nums
* @return {number[]}
*/
// Approach 1: Using a map/object/hashtable to keep track of numbers we've seen before
// Loop through the nums array and add numbers that exist into the map/object
// Loop from 1..nums.length and if a number doesn't exist in the map, add it to result array
// O(N) time, O(N) space
// Approach 2: Using a set
// Loop through numbers [1..n] and add them to set
// Loop through nums and if number is not in set, add it to result array
// O(N) time, O(N) space
var findDisappearedNumbers = function(nums) {
// Initialize a map to keep track of numbers that exist in nums
const numsMap = new Map();
// Loop through the nums array and add numbers that exist into the map
nums.forEach((num) => { numsMap.set(num, true) });
const result = [];
// Loop from 1..nums.length and if a number doesn't exist in the map, add it to result array
for (let i = 1; i < nums.length + 1; i++) {
if (!numsMap.has(i)) {
result.push(i);
}
}
return result;
};