Zero sum interval X29941


Statement
 

pdf   zip

html

Dessign the function intervalo_suma_cero(f, i) that, given a list f of integers and an integer i such that 0 ≤ i < len(f), returns the smallest value ji such that the sum of the elements in f from position i to position j is zero. If there is no such value, it will return -1.

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