Created
October 27, 2017 18:19
-
-
Save jpolvora/931142bd95b43fdc32f228c5d0df2250 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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