Generate Parenthesis Problem

On submitting on coding blocks its showing wrong answer but its working on other compilers.

Here is my code. Also, i have printed the o/p in the correct order , i.e “(” has smaller value than “)”.

#include<bits/stdc++.h>
#define ll long long
using namespace std;

void generateBrackets(char out, int n, int idx, int open, int close) {
if(idx == 2
n) {
out[idx] = ‘\0’;
cout << out << endl;
return;
}
if(close < open) {
out[idx] = ‘)’;
generateBrackets(out, n, idx + 1, open, close + 1);
}
if(open < n) {
out[idx] = ‘(’;
generateBrackets(out, n, idx + 1, open + 1, close);
}
return;
}

int main()
{

#ifndef ONLINE_JUDGE
freopen(“input.txt”,“r”, stdin);
freopen(“output.txt”,“w”, stdout);
#endif

int n; cin >> n;
char out[1000];
int idx = 0;
generateBrackets(out, n, 0, 0, 0);


return 0;

}

hi @deep_01

#ifndef ONLINE_JUDGE
freopen(“input.txt”,“r”, stdin);
freopen(“output.txt”,“w”, stdout);
#endif

remove this, it will work fine…
corrected code -->


It’s passing all test cases now…

hey, is there anything else or shall i mark it as resolved??

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.