Report Offensive Message
really fits into single recursive function. It's like imaginary slider moving from the start to the end of an array. We have 2 sums - Before and After the slider index. Every time slider moves, value of its element is added to the Before sum and is taken from After. Naturally, at the start Before = 0, After = sum of all the elements. That the only time we need to calculate the sum of number of the elements. After that would be only single subtraction/addition. Function keeps calling itself with parameters of slider index and Before and After sums. The function compares sums, increments number of equilibrium indices, if they're equal, and adds slider index value to resulting collection, again, if satisfied. Slider index is incremented, Before and After sums are updated as well. Then the function is called again from itself. Condition of leaving recursion is when slider index reaches the end of an array.