Skip to content

Instantly share code, notes, and snippets.

@jlzapata
Created July 28, 2022 00:07
Show Gist options
  • Save jlzapata/a6e326353aebb4a0e24e3cae9f848210 to your computer and use it in GitHub Desktop.
Save jlzapata/a6e326353aebb4a0e24e3cae9f848210 to your computer and use it in GitHub Desktop.
JalaSoft Test
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