Created
August 1, 2017 10:04
-
-
Save vishvanand/ba2a42ca86d0e904a92255879ad6f83d to your computer and use it in GitHub Desktop.
Gearing up for destruction - google foobar
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
def sweep(spaces, r1): | |
start = r1[0]/r1[1] | |
for i in range(0,len(spaces)): | |
if(spaces[i] - start) < 1: | |
return [-1, -1] | |
start = spaces[i] - start | |
return r1 | |
def answer(lst): | |
spaces = [lst[i+1] - lst[i] for i in range(0,len(lst) - 1)] | |
f_space = sum(spaces[::2]) - sum(spaces[1::2]) | |
print(f_space) | |
if(f_space <= 2): | |
return [-1,-1] | |
r1 = 0 | |
if(len(spaces)%2 == 0): | |
r1 = [2*f_space, 1] | |
else: | |
if(f_space%3 == 0): | |
r1 = [2*f_space/3, 1] | |
else: | |
r1 = [2*f_space, 3] | |
return sweep(spaces, r1) | |
print(answer([4,30,50])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment