Skip to content

Instantly share code, notes, and snippets.

@SourceCode
Last active January 7, 2023 12:12
Show Gist options
  • Save SourceCode/19e32ed8c41c49643ded3a06258d37e7 to your computer and use it in GitHub Desktop.
Save SourceCode/19e32ed8c41c49643ded3a06258d37e7 to your computer and use it in GitHub Desktop.
PermMissingElem - Codibility - C#
using System;
namespace PermMissingElem
{
class Program
{
static void Main(string[] args)
{
int[] A = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18 };
var S = new Solution();
Console.WriteLine($"The missing elem is {S.solution(A)}");
}
}
class Solution
{
public int solution(int[] A)
{
int low = A[0];
int high = A[0];
for(int i = 0; i < A.Length; i++)
{
if (A[i] < low) low = A[i];
if (A[i] > high) high = A[i];
}
while(low < high)
{
if (Array.IndexOf(A, low) == -1) return low;
low++;
}
return low;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment