Generate parentheses

I have followed the implementation from the video provided and still, i am receiving an error on submitting my code.

def generate_parentheses(opening_brackets, closing_brackets, n, s=[]):

if closing_brackets == n:
    print(''.join(s))
    return
else:
    if closing_brackets < opening_brackets:
        
        s.append(')')
        generate_parentheses(opening_brackets, closing_brackets + 1, n, s)
        s.pop()

    if opening_brackets < n:
        s.append('(')
        generate_parentheses(opening_brackets + 1, closing_brackets, n, s)
        s.pop()

return

for n in range(1, 11):
generate_parentheses(0, 0, n)

Hey @A18ML0031

Request you to share your code through the Coding Blocks IDE.
Copy-pasting here can mess up the indentation and makes the debugging process harder.

Waiting for your revert…

Hey @A18ML0031

Sorry for the late reply.
I tried submitting your code and it passed all the test cases.


Were you able to find your mistake?

Oh, Okay. Thankyou so much

1 Like