Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Find the Missing Number (easy)

Problem Statement

We are given an array containing n distinct numbers taken from the range 0 to n. Since the array has only n numbers out of the total n+1 numbers, find the missing number.

Example 1:

Input: [4, 0, 3, 1]
Output: 2

Example 2:

Input: [8, 3, 5, 2, 4, 6, 0, 1]
Output: 7

Constraints:

  • n == nums.length
  • 1 <= n <= 10^4
  • 0 <= nums[i] <= n
  • All the numbers of nums are unique.

Try it yourself

Try solving this question here:

.....

.....

.....

Like the course? Get enrolled and start learning!