Skip to content

Instantly share code, notes, and snippets.

@ta1hia
Created March 26, 2016 02:55
Show Gist options
  • Save ta1hia/d8219c607e2b9feb290f to your computer and use it in GitHub Desktop.
Save ta1hia/d8219c607e2b9feb290f to your computer and use it in GitHub Desktop.
# 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