Python Solution with special cases handled


#1

Here is the complete solution. I have handled special cases such as size=1 array separately. I ended up with lot of penalty points so could not score any points but was satisfied to get a solution that passes the test cases:

def maxset(self, A):
n = len(A)
total = 0
prev = -1
index=[]
l = []

    if n==1:
        if A[0]>=0:
            return [A[0]]
            
    for i in range(n):
        
        if A[i]>=0:
            total+=A[i]
            index.append(A[i])               
            
        if i==n-1 and prev<total:
            return index
            
        if A[i]<0:
            if prev<total:
                prev=total
                l=index
                index=[]
                total=0
            elif prev==total:
                    if len(l)<len(index):
                        l=index
                        index=[]
                    elif len(l)==len(index):
                        if l and index:
                            if A.index(l[0])>A.index(index[0]):
                                l=index
                                index=[]
            else:
                total=0
                index=[]
    return l