Skip to content

Instantly share code, notes, and snippets.

@jpolvora
Created October 27, 2017 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpolvora/931142bd95b43fdc32f228c5d0df2250 to your computer and use it in GitHub Desktop.
Save jpolvora/931142bd95b43fdc32f228c5d0df2250 to your computer and use it in GitHub Desktop.
int avoidObstacles(int[] inputArray)
{
var jump = 2;
var max = inputArray.Max() + 1;
while (jump <= max)
{
int multiplier = 1;
bool success = false;
while (true)
{
var number = jump * multiplier;
if (number > max) break;
if (Array.IndexOf(inputArray, number) != -1)
{
success = false;
break;
}
multiplier++;
success = true;
}
if (success) break;
jump++;
}
return jump;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment