Skip to content

Instantly share code, notes, and snippets.

@oakinogundeji
Created August 5, 2016 11:53
Show Gist options
  • Save oakinogundeji/e78eba28d6c8b2791fceb186e7fec15e to your computer and use it in GitHub Desktop.
Save oakinogundeji/e78eba28d6c8b2791fceb186e7fec15e to your computer and use it in GitHub Desktop.
Solution to the equilibrium index problem
def soln(A):
sumA, prevSum, n = sum(A), 0, len(A)
for i in xrange(n):
rem = sumA - prevSum - A[i]
if prevSum == rem:
return i
else:
prevSum += A[i]
return -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment