Doubt wrong answer coming

int main(){
string s;
cin>>s;
stack st;
int counter=0;
int max=0;
for(int i=0;i<s.length();i++){
if(s[i]==’(’){
st.push(s[i]);
}
else{
if(!st.empty() && st.top()==’(’){
st.pop();
counter=counter+2;
}else{
if(counter>max){
max=counter;
}
counter=0;
}
}
}
cout<<counter;
return 0;
}

This is giving wrong answer.

Also not able to unlock test cases.

Your submission shows that all your test cases were passed.
So you mark your doubt as resolved if it is so.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.