🧞

Hmm...

Something unexpected happened with this submission. Let's see if Genie can help.

Day 1 : Generate Parentheses

mediumRecursion
Given nn pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Parentheses should be sorted, i.e. consider two parentheses with the first position of difference having '(' and ')' then parenthesis with '(' should be printed first.

Input Format:

The first and only line of input contains an integer nn

Output Format:

You need to input the number of combinations CC followed by CC lines each containing the parentheses.

Constraints:

(1n81 \le n \le 8)

Examples:

Example 1:

Input:

1

Output:

1
()

Example 2:

Input:

2

Output:

2
(())
()()

Code

Loading Editor...