Kadane's Algorithm


#1

class Solution:
def flip(self, ls):
sum1,maxSum,si=(0,0,0)
check=False
for index,value in enumerate(ls):
value=1 if value is ‘0’ else -1
sum1=sum1+value
if(sum1<0):
si=index+1
sum1=0
if(sum1>maxSum):
check=True
maxSum=sum1
fs=si
fl=index
if(check==True):
return [fs+1,fl+1]
else:
return []