hi everyone , i guess you guys could also add the matched brackets 2 (ZCO) problem out here. but anyways , i have written a code for it , but it doesnt seem to work , i have been sitting in my pc for hours trying to figure out ,i guess there is some flaw in my logic of finding the depth , pls help.

Edit : I just need to know what logic i can use to find the alternative depth. someone just help me with it pls.

#include using namespace std; int main(){ long long int n,x,brac1count,brac2count,depth =1,depelem,maxdepth=1,maxbrac1=0,maxbrac2=0,brac1,brac2; cin>>n; int arr[n+1] ; for(long long int i=1;i<=n;i++) { cin>>x; arr[i] =x; } if(arr[1]==1) {brac1=brac1count= 1; brac2=brac2count = 0 ; depelem=3;} else { brac1=brac1count =0; brac2=brac2count =1 ; depelem = 1; } for(long long int i=2;i<=n;i++) { if(brac1count==brac2count && brac1count==0) { if(depth>maxdepth) maxdepth =depth; depth =0; } if(arr[i]==depelem) { depth++; if(depelem ==1) depelem =3; else depelem =1; } if(brac1!=0) brac1++; if(brac2!=0) brac2++; if(arr[i] == 1) { if(brac1count==0 && depth ==0) { depth++; depelem = 3; } brac1count++; if(brac1==0) brac1++; } else if(arr[i]== 3) { if(brac2count==0 && depth ==0) { depth++; depelem = 1; } brac2count++; if(brac2==0) brac2++; } else if(arr[i] == 2) { brac1count--; if(brac1count==0) { if(brac1>maxbrac1) { maxbrac1=brac1; } brac1 = 0; } } else { brac2count--; if(brac2count==0) { if(brac2>maxbrac2) maxbrac2 =brac2; brac2 =0; } } } cout< return 0;}