https://prepinsta.com/competitive-advanced-coding/
https://prepinsta.com/interview-preparation/technical-interview-questions/most-asked-coding-questions-in-placements/
https://prepinsta.com/python-program/find-largest-sum-of-contiguous-subarray/
# Find the larget substring with largets sum
#Array = [-1, 8, 1, -7, -1, 5, 1, -3]
#Sub array which will give maximum sum [8, 1]
#Maximum sum = 9
list_a = [1,2,3,4,-4,-5,3,0,-1]
len_list = len(list_a)
max_sum = -1
ans = []
for i in range(len_list):
for j in range(i,len_list):
sum_v = sum(list_a[i:j])
if sum_v > max_sum:
max_sum = sum_v
ans = list_a[i:j]
print(ans)
No comments:
Post a Comment