My issue
can anyone help me with this and explain why this approach is wrong .my code runs for the sample input
My code
#include <stdio.h>
int main(void) {
// your code goes here
int n,fp=1,length=0,l=0,nestdepth=0,c=0,fpmax=1,f=1,p=0;
scanf("%d",&n);
int A[n];
for (int i=0;i<n;i++){
scanf("%d",&A[i]);}
for (int i=0;i<n;i++){ l++;f++;p++;
if(A[i]==1)c++;
if(c>nestdepth){nestdepth=c;fp=i+1;}
if(A[i]==2)c--;
if(c==0){if(length!=l){
if(length<l)length=l;l=0;
f=p-length+1;
if(fpmax<f)fpmax=f;}
}
}
printf("%d %d %d %d",nestdepth,fp,length,fpmax);
return 0;
}
Problem Link: CodeChef: Practical coding for everyone
type or paste code here