i have implememnted a pretty basic logib but getting all answers wrong ,if someone may please point out the mistake
code:Https://ide.codingblocks.com/s/41937
question::Generate Parentheses
https://online.codingblocks.com/player/9713/content/5144
i have implememnted a pretty basic logib but getting all answers wrong ,if someone may please point out the mistake
code:Https://ide.codingblocks.com/s/41937
question::Generate Parentheses
https://online.codingblocks.com/player/9713/content/5144
you have to modify your help function similar to this
vector help(int n)
{
vector ans,cou;
if(n==1)
{
cou.push_back("()");
return cou;
}
ans=help(n-1);
int i;
string s="";
for(i=0;i<=ans.size()-1;i=i+1)
{
s="()"+ans[i]; /// single type to call
cou.push_back(s);
s="("+ans[i]+")";
cou.push_back(s);
}
return cou;
}
in your help function call only ()+ help(n-1) as help(n-1)+ () call lead to duplicate values
Hit like if you get it
Cheers!
But this will miss out the possible balanced parentheses, in the case when n =3,
according to this approach this -> (())() , arrangement will miss out. that is why we need to include the s= help(n-1)+();