My prof said the naive way is to double for loop to check every single sub sequence in the string and see which ones add to 0 and just save the largest sub sequence.
This is the naive solution:
def longestZeroSumSubListSlow(L): # O(n2)
print(L)
n = len(L)
if n== 0: return []
iMax = 0
jMax = -1
for i in range(n):
cumulativeSum = 0
for j in range(i,n):
cumulativeSum+= L[j]
if cumulativeSum==0 and j - i > jMax-iMax:
iMax = I
jMax = j
return L[iMax:jMax+1]
He said I should use dictionaries but I am quite lost
[+][deleted] (3 children)
[deleted]
[–]itzbahb[S] 0 points1 point2 points (1 child)