Hard
All Balanced Brackets
Read n (1–5) and print every string of n pairs of balanced round brackets, in alphabetical order (
( comes before )), one per line. Build them recursively, adding ( while you have some left and ) only when it keeps the string balanced.Input
One integer.
Output
Lines.
Sample 1
Input
3
Output
((())) (()()) (())() ()(()) ()()()
Sample 2
Input
1
Output
()
Output appears here