32 lines
1.1 KiB
Text
32 lines
1.1 KiB
Text
An equilibrium index of a sequence is an index into the sequence such that the sum of elements at lower indices is equal to the sum of elements at higher indices.
|
|
|
|
|
|
For example, in a sequence <big><math>A</math></big>:
|
|
|
|
::::: <big><math>A_0 = -7</math></big>
|
|
::::: <big><math>A_1 = 1</math></big>
|
|
::::: <big><math>A_2 = 5</math></big>
|
|
::::: <big><math>A_3 = 2</math></big>
|
|
::::: <big><math>A_4 = -4</math></big>
|
|
::::: <big><math>A_5 = 3</math></big>
|
|
::::: <big><math>A_6 = 0</math></big>
|
|
|
|
3 is an equilibrium index, because:
|
|
|
|
::::: <big><math>A_0 + A_1 + A_2 = A_4 + A_5 + A_6</math></big>
|
|
|
|
6 is also an equilibrium index, because:
|
|
|
|
::::: <big><math>A_0 + A_1 + A_2 + A_3 + A_4 + A_5 = 0</math></big>
|
|
|
|
(sum of zero elements is zero)
|
|
|
|
7 is not an equilibrium index, because it is not a valid index of sequence <big><math>A</math></big>.
|
|
|
|
|
|
;Task;
|
|
Write a function that, given a sequence, returns its equilibrium indices (if any).
|
|
|
|
Assume that the sequence may be very long.
|
|
<br><br>
|
|
|