C# Perm Missing Element
static int PermMissingElement(int[] a)
{
var sorted = (int[])a.Clone();
Array.Sort(sorted);
for (int k = 0; k < sorted.Length; k++)
{
if (sorted[k] != k + 1)
{
return k + 1;
}
}
return sorted.Length + 1;
}
This uses the expected sum of 1..N+1 and subtracts the actual sum to find the missing value.