O(n) simple solution


#1

Comment body goes here.vector Solution::flip(string a) {
int l = -1, r = -1, y = -1, z = -1, x = 0, m = 0;/* l and r to store indexes, and y, z for temp indexes, m for max length of 0’s and x for temporary length score of 0’s adn 1;s*/
for(int i = 0; i < a.length(); i ++){
if(a[i] == ‘0’){
x ++;
if(y == -1){
y = i + 1;
}
z = i + 1;
if(x > m){
m = x ;
l = y;
r = z;

        }
    }
    else{
        x--;
        if(x < 0){
            x = 0;
            y= -1;
        }
    }
}
if(x > m){
    m = x;
    l = y;
    r = z;
}
vector<int>v;
if(m > 0){
v.push_back(l);
v.push_back(r);
}
return v;

}