Missing Number - aloalgo.com

Missing Number

Easy
New!

You are given an array nums that contains n unique numbers.

Your task is to identify and return the single number that is missing from the range 0 to n (inclusive).

You may assume that:

  • The array nums always contains unique numbers.
  • Exactly one number from the full sequence 0, 1, ..., n will be absent from the nums array.

Return the missing number.

Example 1

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

The array [2, 3, 1] is missing 0.

Example 2

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

The array [3, 0, 1] is missing 2.

Example 3

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

The array [1, 0, 2, 3] is missing 4.

Loading...

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!