The question was "Max Continuous Series of 1s"
You are given an array of 1s and 0s. And you are given an integer M, which signifies number of flips allowed.
Find the position of zeros which when flipped will produce maximum continuous series of 1s.
I used sliding window approach to solve the answer, but there is something I noticed that if I write start=i;end=j;
its wrong, but start=i,end=j;
is right.
What's the difference between the execution of them?
vector<int> Solution::maxone(vector<int> &A, int B) {
int n=A.size();
int start=0,end=0,count=0,i,j;
for(i=0,j=0;j<n;){
if(B>=0 && !A[j++])
B--;
if(B<0 && !A[i++])
B++;
if(end-start<j-i)
start=i,end=j; // Here I get wrong ans if I write start=i;end=j;
}
vector<int> v;
while(start<end)
v.push_back(start++);
return v;
}