ef genp(cb,ob,n,s=[]):
if cb==n:
print (’’.join(s))
return
else:
if ob>cb:
s.append(’)’)
genp(ob,cb+1,n,s)
s.pop()
if ob<cb:
s.append(’(’)
genp(ob+1,cb,n,s)
s.pop()
return
print(genp(0,0,3))
ef genp(cb,ob,n,s=[]):
if cb==n:
print (’’.join(s))
return
else:
if ob>cb:
s.append(’)’)
genp(ob,cb+1,n,s)
s.pop()
if ob<cb:
s.append(’(’)
genp(ob+1,cb,n,s)
s.pop()
return
print(genp(0,0,3))
It’s great you got the logic for the problem, and you nearly succeeded in coding it.
These are few silly mistakes you did:
Hope this cleared your doubt Keep coding keep growing.
def genp(ob,cb,n,s=[]):
if cb==n:
print (’’.join(s))
return
else:
if ob>cb:
s.append(’)’)
genp(ob,cb+1,n,s)
s.pop()
if ob<cb:
s.append(’(’)
genp(ob+1,cb,n,s)
s.pop()
return
genp(0,0,3)
Are you still facing any problem or not. If not please close the doubt and keep coding.
Or if your doubt is not cleared yet, than plz respond, we would love to clear that.