218. Generate Parentheses
MediumBacktracking
Print all valid combinations of n pairs of parentheses in lexicographic order ('(' < ')'), one per line.
Input format
A single integer n.
Output format
The valid strings.
Example 1
Input
3
Output
((())) (()()) (())() ()(()) ()()()
Example 2
Input
1
Output
()
Constraints
1 ≤ n ≤ 8
Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.
Loading the MyLoginn IDE…