import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int na[]=new int[n];
for(int i=0;i<n;i++){
na[i]=s.nextInt();
}
calcNdep(na);
calcMaxSeq(na);
}
static void calcNdep(int naa[])
{
int dep=0;
int maxd=0;
int fpos=0;
for(int i=0;i<naa.length;i++){
if(naa[i]==2){
if(dep>maxd){
maxd=dep;
fpos=i;
}
dep=0;
}
else if(naa[i]==1) {
dep++;
}
}
System.out.print(maxd+" "+fpos+" ");
}
static void calcMaxSeq(int naa[])
{
int no=0;
int nt=0;
int fpos=0;
int mxlsq=0;
for(int i=0;i<naa.length;i++){
int num=naa[i];
if(num==1){
no++;
}
else if(num==2){
nt++;
}
if(i%2!=0){
if(no==nt){
int lmsq=no*2;
if(lmsq>mxlsq){
mxlsq=lmsq;
fpos=i-lmsq+2;
}
no=0;
nt=0;
lmsq=0;
}
}
}
System.out.print(mxlsq+" "+fpos);
}
}
Problem Link:www.codechef.com/ZCOPRAC/problems/ZCO12001
Why does my solution get AC only for few test cases but not for the others?
Precisely, my solution gets accepted only in 5/15 test cases.
Please help!