Generate Balanced Parentheses
Mediumjavapythonccppjavascript
Given N pairs of parentheses, generate every string of 2N characters in which every opening parenthesis is correctly matched.
Input Format
A single line containing the integer N.
Output Format
Print all valid strings, one per line, in lexicographic order (treating ( as smaller than )).
Example 1
Input
3
Output
((())) (()()) (())() ()(()) ()()()
Explanation: These are all valid ways to arrange three pairs of parentheses.
- 1 <= N <= 8