Showing wrong ans

#include
using namespace std;

int longest(int a[],int n,int k){
int cnt0 = 0;
int l = 0;
int max_len = 0;
for(int i=0;i<n;i++){
if(a[i]==0){
cnt0++;
}
while(cnt0>k){
if(a[l]==0){
cnt0–;
}
l++;
}
max_len=max(max_len,i-l+1);
}
return max_len;
}

int main() {
int n,k;

cin >>n>>k;
int a[n];
for(int i=0;i<n;i++){
	cin>>a[i];
}
cout<<longest(a,n,k);
return 0;

}

Hello @mansi25 this is beacuse you have to print the final array after making change in array where you can find the maximum one together.

check this is the correct code:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.