Skip to content

Instantly share code, notes, and snippets.

@gbazilio
Created January 29, 2017 13:34
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 gbazilio/5fa91ef21d2f4c1dfc32043760c60bf0 to your computer and use it in GitHub Desktop.
Save gbazilio/5fa91ef21d2f4c1dfc32043760c60bf0 to your computer and use it in GitHub Desktop.
Codility - Passing cars
def solution(A):
passing_cars = 0
east_cars = 0
for index in xrange(len(A)):
if A[index] == 1:
passing_cars += east_cars
else:
east_cars += 1
if passing_cars > 1000000000:
return -1
return passing_cars if passing_cars <= 1000000000 else -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment