PIXELBANKv8.2.1
Menu

Missing Number

Given an array containing n distinct numbers from 0, 1, 2, ..., n, find the one that is missing.

Example:

Input:
3,0,1
Output:
2
Reasoning:
  • The input array is [3, 0, 1], containing n = 3 distinct numbers.
  • We notice that the array should contain numbers from 0 to n, so the complete set should be [0, 1, 2, 3].
  • Comparing the input array to the complete set, we find that the number 22 is missing.
  • The final output is therefore 2.

Constraints:

  • 1 <= n <= 10^4
  • All numbers are unique
  • 0 <= nums[i] <= n
Editor

Test Results

0/0
Run code to see test results.