Generate parentheses that are valid.Why is this code not getting accepted?

#include<bits/stdc++.h>
using namespace std;
void generateparentheses(int n,int i,int oc,int cc,char output)
{
//base case
if(i==2
n)
{
output[i]=’\0’;
cout<<output<<endl;
return;
}

    if(oc<n)
    {
        output[i]='(';
        generateparentheses(n,i+1,oc+1,cc,output);
    }
    if(cc<oc)
    {
        output[i]=')';
        generateparentheses(n,i+1,oc,cc+1,output);
    }
    return;

}
int main()
{

int n;
cin>>n;
char output[1000];
int i=0;
generateparentheses(n,i,0,0,output);

}

@Kshitij-Taneja-2315806971864318 the order of sample output does not match your current output. Modify your code such that you first try to place ) and then try to place ( to match the sample output.

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.