Zero sum interval X29941


Statement
 

pdf   zip

Dessign the function @intervalo_suma_cero(f, i)@ that, given a list ff of integers and an integer ii such that 0i<len(f)0 \le i < len(f), returns the smallest value jij \ge i such that the sum of the elements in ff from position ii to position jj is zero. If there is no such value, it will return -1.

Sample session

Sample session
>>> intervalo_suma_cero([1,2,3,-5,-3,2,8,-8],0)
5
>>> intervalo_suma_cero([1,2,3,-5,-3,2,8,-8],1)
3
>>> intervalo_suma_cero([1,2,3,-5,-3,2,8,-8],5)
-1
Information
Author
InfBesos
Language
English
Other languages
Catalan Spanish
Official solutions
Python
User solutions
Python