Coding problem
The missing number
The task
A ticket printer numbers its tickets 0, 1, 2 and so on. At the end of a session the stubs come back in any order, and exactly one ticket is missing.
Complete FindMissing(int[] values). The array holds n different numbers, all taken from the range 0 to n (n is the array's length), so exactly one number of that range is absent. Return it.
Signature
public static int FindMissing(int[] values)
Examples
[4, 2, 1, 0]→3. Four values, so the range is 0 to 4, and 3 is the one not there.[0]→1. One value, so the range is 0 to 1.
Limits: Up to 100,000 values, in any order.
The tests check: the missing number at the start, in the middle and at the end, a one-value array, values in falling order, and a 70,000-value array where n × (n + 1) / 2 does not fit in an int.
Hints
The solution opens by itself when all tests pass. You remember more if you try first.
Sign in to see the solutionYour code
Already included: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks;
public static class Solution
{
// values holds n different numbers from 0 to n; returns the one number of that range that is absent.
public static int FindMissing(int[] values)
{
throw new NotImplementedException();
}
}Sign in to run and submit your code. It stays here while you do.