Skip to content

Instantly share code, notes, and snippets.

@5minho
Created May 6, 2018 17:19
Show Gist options
  • Save 5minho/5c2405c9d37ad0137fca6b8c1b28d91c to your computer and use it in GitHub Desktop.
Save 5minho/5c2405c9d37ad0137fca6b8c1b28d91c to your computer and use it in GitHub Desktop.
Codility TapeEquilibrium
def solution(A):
left_sum, right_sum = A[0], sum(A[1:])
result = abs(left_sum - right_sum)
for x in range(1, len(A) - 1):
left_sum, right_sum = left_sum + A[x], right_sum - A[x]
result = min(result, abs(left_sum - right_sum))
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment