Generate parentheses

what is wrong in my approach?

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

void func(int left,int right,string s)
{
if(left==0 && right==0)
cout<<s<<endl;
if(left >0)
func(left-1,right,s+"(");
if(left < right)
func(left,right-1,s+")");
}

int main()
{
int n;
cin>>n;
string s="";
func(n,n,s);
}

Hi Kartikay
Your approach is correct, only the ordering of display needs to be corrected as per question.
Your Code’s Output is:
(())
()()
The Expected Output is:
()()
(())

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.