Easy working solution, Understandable


#1

vector Solution::flip(string A) {

vector<int>v;
vector<int>ans;
int sum=0;

for(int  i =0 ; i< A.size();i++)
{
    
    if((A[i])-'0')
    v.push_back(-1);
    else 
    v.push_back(1);
    sum+=v[i];
}
if(sum==-(A.size()))
    return ans;
int start=0, end=0 ,mx=0,s=0;
int cur_m = INT_MIN;
for(int i = 0 ; i<A.size();i++)
{
    mx+=v[i];
    if(mx>cur_m)
    {
        cur_m = mx;
        start = s;
        end = i;
    }
    if(mx<0)
    {
        mx = 0;
        s = i+1;
    }
}
ans.push_back(start+1);
ans.push_back(end+1);
return ans;

}