Doubt in CODIGO06 question

Link to question :- CodeChef: Practical coding for everyone
Here is my code:-
#include <bits/stdc++.h>
using namespace std;

int main() {
// your code goes here
long long int t,n;
cin>>t;
while(t–){
cin>>n;
long long int a[n],res=0;
for(long long int i=0;i<n;i++)
cin>>a[i];
for(long long int i=0;i<n;i++){
if(a[i]==1){
for(long long int j=i+1;j<n;j++){
if(a[j]-a[j-1]!=1)
break;
else
res=max(res,a[j]);
}
}
}
cout<<res<<endl;
}
return 0;
}

Please can anyone rectify my error in the code as I’m unable to. The sample test cases are also working fine.

The problem in your code is that you are initializing result with 0 and updating it inside the second loop. Consider the example :
5
2 3 4 5 1
Your code will give 0 as output, but the actual output is 1.
I have corrected your code and it gets accepted.
https://www.codechef.com/viewsolution/41940020

Thnx bro I have solved again and after taking edge cases I came to the same conclusion as you did. I’ve corrected my code.