categories: computer science
Welcome,
Below you will find a video with a detailed explanation of the algorithm for determining the maximum subarray sum. Its operation, time complexity, and usefulness. Below you will also find ready-to-use code that you can copy if needed.
Code:
tablica = [1, -3, 5, 2, -1, -1, 2, -2, 5, 9, 2]
sumaTeraz = tablica[0]
sumaMax = 0
for i in range(1, len(tablica)):
if sumaTeraz < 0:
sumaTeraz = tablica[i]
else:
sumaTeraz += tablica[i]
sumaMax = max(sumaTeraz, sumaMax)
print(str(sumaMax))
Video:
Thank you for reading!
Read more