Easy 0 solved 0% acceptance

Missing Number

Find the one number missing from 0..n.

Problem

The list holds n distinct numbers taken from 0, 1, …, n, so exactly one number in that range is missing. Find it. (Hint: compare the expected total with the actual total.)

Implement missing_number(numbers).

Input

numbers: n distinct numbers from 0 to n.

Output

Return the missing number.

Constraints

0 ≤ n ≤ 100,000

Examples

Example 1
Input:
numbers = [3, 0, 1]

Expected output:
expected = 2
Input:
std::vector<long long> numbers = {3, 0, 1};

Expected output:
long long expected = 2;
Input:
long[] numbers = new long[] {3, 0, 1};

Expected output:
long expected = 2;

Explanation

n = 3, so the range is 0–3; 2 is missing.

Example 2
Input:
numbers = [0]

Expected output:
expected = 1
Input:
std::vector<long long> numbers = {0};

Expected output:
long long expected = 1;
Input:
long[] numbers = new long[] {0};

Expected output:
long expected = 1;

Explanation

n = 1 and the range is 0–1; 1 is missing.

References

This challenge is adapted for CodeUtility. Follow the statement and constraints above.

Learn from others

Community solutions

No published solutions yet. Solve this challenge to share the first one.