Question DSA-REC-0019
HardWhat is the output of this code?
def gen(n, s="", o=0, c=0):
if len(s) == 2 * n:
return [s]
out = []
if o < n:
out += gen(n, s + "(", o + 1, c)
if c < o:
out += gen(n, s + ")", o, c + 1)
return out
print(" ".join(gen(3)))
- A.
(()) ()()
- B.
((())) (()()) (())() ()(()) ()()()
- C.
Sign up free to see the answer and a step-by-step explanation.