Given a list. I have to create sublists having at least one element, and then return the sublist having maximum sum.
here is what I tried :
class Solution:
def maxSubArray(self, nums: List[int]) -> int:
lists=[[]]
for i in range(1,len(nums)+1):
for j in range(1,i):
lists.append(nums[j:i])
new_list=lists
sum_list=[]
for k in range(1,len(new_list)):
sum1=sum(new_list[k])
sum_list.append(sum1)
return max(sum_list)
this is giving this error :
ValueError: max() arg is an empty sequence
How do I tweek my code to remove the empty sublist.