Balanced sum X45803


Statement
 

pdf   zip

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

Sample session

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