Very nice problem, need good observational skill using recursion


#1

//make recursive tree and observe

void solve(int open, int close, string op,vector &v)
{
if(open==0 && close==0)
{
v.push_back(op);
return;
}
if(open!=0)
{
string op1=op;
op1.push_back(’(’);
solve(open-1,close,op1,v);
}
if(close>open)
{
string op2=op;
op2.push_back(’)’);
solve(open,close-1,op2,v);
}
return;
}

vector Solution::generateParenthesis(int A) {
int open=A;
int close=A;
vector v;
string op="";
solve(open,close,op,v);
return v;
}


#2

Aditya Verma is so cool:wink: