i used stacks to solve this problem.it's working on some test cases and giving wa on some . i used the stack s to find nesting depth and first position that achieves the nesting depth and the stack pto find the length of the maximum sequence between matching brackets and the first position where such a maximum length sequence occurs. Here's my code

#include <bits/stdc++.h>using namespace std;int main() {stack <int> s;stack <int> p;int n,a,count=0,temp=0,pos=0,temp2=0;int temp3=0,len=0,c=0,pos2=0;cin>>n;while(n--){cin>>a;if(a==1){s.push(1);count++;temp2++;p.push(1);c++;temp3++;

Read more… (73 words)