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