#K54217. Generate Balanced Parentheses
Generate Balanced Parentheses
Generate Balanced Parentheses
Given a positive integer (N), generate all combinations of (N) pairs of balanced parentheses. A combination is considered balanced if every opening parenthesis has a corresponding closing parenthesis and the pairs are well-nested. The returned list must be in dictionary order. For example, when (N = 3), the valid combinations are: (((()))), ((()())), ((())()), (()(())), and (()()()).
inputFormat
The input consists of a single integer (N) (where (1 \leq N \leq 10)) provided via standard input.
outputFormat
Output all valid combinations of balanced parentheses in dictionary order, each on a separate line, via standard output.## sample
1
()
</p>