Good morning! Here's our prompt for today.
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)
Try to solve this here or in Interactive Mode.
How do I practice this challenge?
xxxxxxxxxx
38
'PASSED: missingNumbers([3, 7, 9, 19]) should equal [ 4, 5, 6, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18 ]'
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(
missingNumbers([3, 7, 9, 19]),
[4, 5, 6, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18]
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment
Here's a video of us explaining the solution.
To change the speed of the video or see it in full screen, click the icons to the right of the progress bar.

Here's our guided, illustrated walk-through.
How do I use this guide?