Mark As Completed Discussion

One Pager Cheat Sheet

  • Write a function missingNumbers that takes an array of continuous numbers and returns the missing integers in O(n) time with O(1) space complexity.
  • The key to finding the missing number in an array is to make sure that the array is sorted in ascending order, then check that each adjacent number is incrementing by 1, or use a while loop to append the appropriate numbers.
  • This approach is harder to grok, however it can be optimized by iterating through both arrays simultaneously, resulting in an O(n) runtime complexity.

This is our final solution.

To visualize the solution and step through the below code, click Visualize the Solution on the right-side menu or the VISUALIZE button in Interactive Mode.

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Great job getting through this. Let's move on.

If you had any problems with this tutorial, check out the main forum thread here.