Facebook Pixel

Find Missing Number

JavaScript
easy
10 mins

You are given an array containing n distinct numbers taken from the range 0 to n. This means the array should ideally contain all numbers from 0 to n, but one number is missing. Your task is to find and return that missing number.

Input: An array of n integers where each integer is unique and lies between 0 and n (inclusive) except for one missing number.
Output: Return the missing number.

Example Inputs & Outputs

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

Constraints & Edge Cases

  • The array contains exactly n numbers.
  • All numbers are unique.
  • Numbers are in the range 0 to n.
  • Only one number is missing from the sequence.
  • The array may be in any order.
  • Edge case: missing number could be 0 or n.

Solve Similar questions 🔥

Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.