Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# you can write to stdout for debugging purposes, e.g.
# print "this is a debug message"
def solution(A):
# write your code in Python 2.7
L = len(A)
n = 0
if L == 1:
return 0
for i in range(L-2, -1, -1):
if A[i]: # 1 or west
A[i] = A[i+1] + 1
else: # 0 or east
A[i] = A[i+1]
n = n + A[i]
if n > 1000000000:
return -1
return n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.