Skip to content

Instantly share code, notes, and snippets.

@vishvanand
Created August 1, 2017 10:04
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 vishvanand/ba2a42ca86d0e904a92255879ad6f83d to your computer and use it in GitHub Desktop.
Save vishvanand/ba2a42ca86d0e904a92255879ad6f83d to your computer and use it in GitHub Desktop.
Gearing up for destruction - google foobar
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