Created
January 29, 2017 13:34
-
-
Save gbazilio/5fa91ef21d2f4c1dfc32043760c60bf0 to your computer and use it in GitHub Desktop.
Codility - Passing cars
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 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