Balanced sum X45803


Statement
 

pdf   zip

html

Design the function suma_equilibrada(f) that, given a list of integers f, returns the smallest index i such that the sum of the elements of f from the first position until the position i is equal to the sum of the subsequent elements. Note that i has to be a valid position in the list. If this position does not exist, the function will return -1.

Sample session
>>> suma_equilibrada([1, 1, 1, 1])
1
>>> suma_equilibrada([10, 10, 7, 3, 30])
3
>>> suma_equilibrada([10, 20])
-1
>>> suma_equilibrada([-3, 5, -2])
2
>>> suma_equilibrada([0])
0
>>> suma_equilibrada([])
-1
Information
Author
InfBesos
Language
English
Other languages
Catalan Spanish
Official solutions
Python
User solutions
Python