Job Bounties : Dynamic Programming

Can you please provide the implementation of this problem

@aman_ishan hey here is small piece of code for your reference ,take input yourself and dry run it you will get it.
stack<pair<ll,ll>> S;
S.push({(s[0]==’(’?0:1),0});
ll dp[n+1]={};
for(i=1;i<n;i++){
if(s[i]==’)’){
cnt=0;
if(!S.empty()){
if(S.top().F==0){
dp[S.top().S]=2;
dp[i]=2;
S.pop();
}
else{
S.push({1,i});
}
}
else{
S.push({1,i});
}
}
else{
S.push({0,i});
}
}

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.