n = int(input())
def printParathesis(n,cB,oB,opSoFar):
if cB==n:
print(opSoFar)
opSoFar=’’
return
if oB<n:
printParathesis(n,cB,oB+1,opSoFar+’(’)
if cB<oB:
printParathesis(n,cB+1,oB,opSoFar+’)’)
printParathesis(n,0,0,’’)
n = int(input())
def printParathesis(n,cB,oB,opSoFar):
if cB==n:
print(opSoFar)
opSoFar=’’
return
if oB<n:
printParathesis(n,cB,oB+1,opSoFar+’(’)
if cB<oB:
printParathesis(n,cB+1,oB,opSoFar+’)’)
printParathesis(n,0,0,’’)
hey @Mohit2000 ,
Your output is reverse order.
Your current output is
((()))
(()())
(())()
()(())
()()()
Whereas it needs to be
()()()
()(())
(())()
(()())
((()))
Just change your logic to reverse it.