I was doing the google foobar challenge but ran out of time on the following challenge i am trying to see what i did wrong.
Challenge
As
from fractions import Fraction
def answer(a):
l = len(a)
if(not a or l == 1): return [-1,-1]
s = (a[l-1] - a[0]) if (l % 2 == 0) else (-a[l-1]-a[0]);
if(l > 2):
for i in range(1, l-1): s+= 2 * (-1)**(i+1) * a[i]
v = Fraction(2*(float(s)/3 if (l%2==0) else float(s))).limit_denominator();
c = v;
for i in range(0, l-2):
d = a[i+1] - a[i]
n = d - c
if(c < 1 or n < 1): return [-1,-1]
else: c = n
return [v.numerator, v.denominator];