nikunjsoni

1004

Apr 10th, 2021
90
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     int longestOnes(vector<int>& A, int K) {
  4.         int count, left, right, n=A.size(), ans;
  5.         count = ans = 0;
  6.        
  7.         for(left=0,right=0; right<n; right++){
  8.             if(A[right] == 0) count++;
  9.            
  10.             while(count > K)
  11.                 if(A[left++] == 0) count--;
  12.             ans =  max(ans, right-left+1);
  13.         }
  14.         return ans;
  15.     }
  16. };
RAW Paste Data