Created
July 28, 2022 00:07
-
-
Save jlzapata/a6e326353aebb4a0e24e3cae9f848210 to your computer and use it in GitHub Desktop.
JalaSoft Test
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
namespace TestJalaSoft | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string[] stringNumbers = new string[] { "13", "11", "9", "10", "12", "15" }; | |
int[] numbers = new int[stringNumbers.Length]; | |
for (int i = 0; i < numbers.Length; i++) | |
{ | |
numbers[i] = Convert.ToInt32(stringNumbers[i]); | |
} | |
Console.WriteLine(FindLostNumber(numbers)); | |
} | |
static int FindLostNumber(int[] numbers) | |
{ | |
if (numbers.Length < 1) | |
{ | |
return 0; | |
} | |
Array.Sort(numbers); | |
int previousNumber = numbers[0]; | |
for (int i = 1; i < numbers.Length; i++) | |
{ | |
if (numbers[i] != previousNumber + 1) | |
{ | |
return previousNumber + 1; | |
} | |
previousNumber = numbers[i]; | |
} | |
return 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment