In the question where we need to generate parenthesis, the code I wrote is working on jupyter-notebook. Also, it showing success when I run the code but when I submit it, it says wrong answer for all the test cases. I can’t seem to find the error.
Code:
def genParenthesis(openB, closeB, n, l=[]):
if(closeB == n):
print(''.join(l))
else:
if(openB>closeB):
l.append(')')
genParenthesis(openB, closeB+1, n, l)
l.pop()
if(openB<n):
l.append('(')
genParenthesis(openB+1, closeB, n, l)
l.pop()
return
n = int(input())
if n>=1 & n<=11:
genParenthesis(0, 0, n)