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]

Description

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)
JAVASCRIPT
OUTPUT
Results will appear here.