PIXELBANKv9.1.0
Menu

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
  • 0 <= nums[i] <= n
  • All numbers are unique
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Missing Number - Easy | PixelBank