Equilibrium index of an array is an index such that the sum of elements at lower indexes is equal to the sum of elements at higher indexes. For example, in an array A:
(A[0] + A[1] + ... + A[i-1]) = (A[i+1] + A[i+2] + ... + A[n-1])
where 0 < i < n - 1
Given an array of integers, find the list of equilibrium indexes in it.
Let array arr
equal to [ 0, -3, 5, -4, -2, 3, 1, 0 ]
. The equilibrium index found at index 0
, 3
and 7
:
0 = (-3) + 5 + (-4) + (-2) + 3 + 1 + 0
(-3) = (-4) + (-2) + 3 + 1 + 0
0 + (-3) + 5 + (-4) + (-2) + 3 + 1 = 0
Therefore the solution should return [ 0, 3, 7 ]
.