Sliding Window Solutn


#1
int Solution::solve(vector<int> &A, int B) {
    int start=0,good=0,bad=0,res=0;
     for(int i=0;i<A.size();i++)
     {
         if(A[i]==1) good++;
         else bad++;
         while(bad>B)
         {
             if(A[start]==1) good--;
             else bad--;
             start++;
         }
         res=max(res,good+bad);
     }
     return res;
}