Last active
January 7, 2023 12:12
-
-
Save SourceCode/19e32ed8c41c49643ded3a06258d37e7 to your computer and use it in GitHub Desktop.
PermMissingElem - Codibility - C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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