Efficient, easy to understand , well commented c++ sol

programming
amazon
interview-questions
Tags: #<Tag:0x00007f241e22ef40> #<Tag:0x00007f241e22ee00> #<Tag:0x00007f241e22ec98>

#1

int Solution::solve(vector &A, int B) {
int zs=0,max=0,c=0,cmax=0;//zs is zero start
for(int i=0;i<A.size();i++)
{
if(A[i]==1)
cmax++;
else
{
if(c==0)
{
zs=i;//for the first time we set the zs position
c++;
cmax++;
}
else
{
if(c==B)//no. of zeroes equal to B
{
cmax=i-zs;
do
zs++;
while(zs<A.size() && A[zs]!=0);
}
else
{
c++;
cmax++;
}
}
}
if(cmax>max)
max=cmax;
}
return max;
}