For ‘N’ = 3, All possible combinations are: ((())) (()()) (())() ()(()) ()()()
Input consists of a single line containing a single integer ‘N’, representing the number of pairs in the parentheses.
Print list of strings denoting all possible combinations for the given integer in a lexicographically ascending order.
You are not required to print anything, it has already been taken care of. Just implement the function.
We will try to fix both the opening and closing brackets at each index if it can lead to a valid parenthesis. For a parenthesis to be valid, at each index the number of the opening bracket in the prefix of that index should be greater than or equal to the number of closing brackets.