I am not able to pass a test case.Someone please tell what must I be missing
#include
using namespace std;
void flipAndPrint(long long arr[],long long n,long long k)
{
long long l=0;
long long zero_count=0,max_len=0,maxr=0,maxl=0;
for (long long i = 0; i < n; i++) {
if (arr[i] == 0)
zero_count++;
// If there are more 0's move
// left point for current ending
// point.
while (zero_count> k) {
if (arr[l] == 0)
zero_count--;
l++;
}
if(i-l+1>max_len)
{
maxl=l;
maxr=i;
}
max_len = max(max_len, i - l + 1);
}
cout<<max_len<<endl;
for(long long i=0;i<n;i++)
{
if(i>=maxl && i<=maxr)
arr[i]=1;
}
for(long long i=0;i<n;i++)
cout<<arr[i]<<" ";
// cout<<endl;
}
int main() {
long long n,k;
cin>>n>>k;
long long arr[n];
for(long long i=0;i<n;i++)
{
cin>>arr[i];
}
flipAndPrint(arr,n,k);
}