Find Missing Number in Array (Medium)
Good morning! Here's our prompt for today.
You may see this problem at Amazon, Doordash, Oracle, Wework, Lyft, Snap, Spotify, Symantec, Wish, Tanium, Invision, Benchling, Appian, Mozilla, Dell, and Qualtrics.
We're given an array of continuous numbers that should increment sequentially by 1
, which just means that we expect a sequence like:
[1, 2, 3, 4, 5, 6, 7]
However, we notice that there are some missing numbers in the sequence.
[1, 2, 4, 5, 7]

Can you write a method missingNumbers
that takes an array of continuous numbers and returns the missing integers?
JAVASCRIPT
1missingNumbers([1, 2, 4, 5, 7]);
2// [3, 6]
Constraints
- Length of the array <=
100000
- The array will always contain non negative integers (including
0
) - Expected time complexity :
O(n)
- Expected space complexity :
O(1)
xxxxxxxxxx
38
var assert = require('assert');
function missingNumbers(numArr) {
let missing = [];
return missing;
}
try {
assert.deepEqual(missingNumbers([0, 1, 3]), [2]);
console.log('PASSED: ' + 'missingNumbers([0, 1, 3]) should equal [2]');
} catch (err) {
console.log(err);
}
try {
assert.deepEqual(missingNumbers([10, 11, 14, 17]), [12, 13, 15, 16]);
console.log(
'PASSED: missingNumbers([10, 11, 14, 17]) should equal [ 12, 13, 15, 16 ]'
);
} catch (err) {
console.log(err);
}
try {
assert.deepEqual(
OUTPUT
Results will appear here.