Chef and subarray testcase help

This is my code plz check

#include<bits/stdc++.h>
using namespace std;
int main(){

ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n;
cin>>n;
long long int a[n];
for(int i=0;i<n;i++){
    cin>>a[i];
}
long long int sum=0,max=INT_MIN;
for(int i=0;i<n;i++) {
    if(a[i]!=0){
        sum++;
    }
    else{
        if(max<=sum){
            max = sum;
        }
        sum = 0;
    }
}
cout<<max;
return 0;

}

all provided testcase passes provided in question

You aren’t updating answer for the subarray which contains the last element ( if such a subarray exists )

Testcases for which this will fail

4
1 1 1 1

and

4
1 0 1 1
1 Like

thank u