


For N = 1, there is only one sequence of balanced parentheses, ‘()’.
For N = 2, all sequences of balanced parentheses are ‘()()’, ‘(())’.
The first line of input contains a single integer T, representing the number of test cases or queries to be run. Then the T test cases follow.
The first line and only line of each test case contain a positive integer 'N'.
For every test case, print all possible sequences of 'N' pairs of balanced parentheses separated by single-spacing.
The output of each test case is printed in a separate line.
You do not need to print anything. It has already been taken care of.
1 <= T <= 10
1 <= N <= 11
We have N pairs of parentheses, which means the length of the sequence will be 2 * N.
To form a sequence of parentheses, we will iterate on the indices and place either of the parenthesis [‘(‘ or ‘)’].
Make a list ‘ans’ which will store all possible sequences of balanced parentheses.
Let’s define a function balancedParenthesesHelper(i, Str, N), where i is the current index, Str is the sequence of parentheses formed till (i-1)th index.
Base case:
If i is equal to 2*N, check whether the sequence is balanced or not.
Next Recursive States:
We have N pairs of parentheses, which means the length of the sequence will be 2 * N.
To form a sequence of balanced parentheses, we will iterate on the indices and place either of the parenthesis:
Make a list ‘ans’ which will store all possible sequences of balanced parentheses.
Let’s define a function balancedParenthesesHelper(i, Str, O, C, N), where i is the current index, Str is the sequence of parentheses formed till (i-1)th index, O is the count of opening parentheses, C is the count of closing parentheses.
Base case: if i is equal to 2*N, add the sequence in the ‘ans’ list and return.
Recursive States:
Pair Product Div by K
Pair Product Div by K
Merge Two Sorted Arrays Without Extra Space
Merge Two Sorted Arrays Without Extra Space
Co-Prime
First Digit One
Special Digit Numbers