Advertisement
cardel

Largest subarray sum

May 15th, 2022
1,425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. """
  2. Carlos A Delgado S
  3. Suma más larga
  4. """
  5.  
  6. def index_largest_sum(a):
  7.     n = len(a)
  8.  
  9.     ini = 0
  10.     fin = 0
  11.     maxi = float("-inf")
  12.     for i in range(n):
  13.         suma = 0
  14.         for j in range(i,n):
  15.             suma+=a[j]
  16.             if suma>maxi:
  17.                 maxi = suma
  18.                 x = i
  19.                 y = j
  20.    
  21.     return x,y
  22.  
  23. print(index_largest_sum([-1,9,0,8,-5,6,-24]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement