Find Missing Number

One problem I tried avoiding was the missing number problem. I did not have confidence in myself to find the actual missing integer in the array. However with a bit of research and resources available to me online I was able to stomach this problem. This problem is number 268 “Missing Number” posted in Leetcode. It states “Given array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.” Here is a closer look at the problem.

Here are a few examples and explanations below for a better perspective.

Deeper Dive Into the Problem.

I created a variable and set it to 0. The purpose of this is to use this variable to increment the numbers in the array and get us one step closer to the problem. Here’s a step-by-step below.

I began to start looping through the entire array. Going through each number. Once that has been established I decided to increment the variable created earlier to the current number. Furthermore, since we are going from the range I decided to subtract the index from the number to filter out that particular missing number. Here’s a closer look below.

Once completed I subtracted the missing number from the length.

Thanks for reading. Any questions leave a comment.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store