Simple solution o(n) and O(1) ||c++


#1

vector Solution::flip(string A) {
int meh=0,m=INT_MIN,l=1,r=1,l1=1,count=0;
for(int i=0;i<A.size();i++)
{
if(A[i]==‘0’)
{
meh++;
count++;
if(m<meh)
{
m=meh;
r=i+1;l=l1;
}
}
else
{
meh–;
if(meh<0)
{
meh=0;
l1=i+2;
}
}
}
if(count==0)
return {};
return {l,r};
}