<p>Given <code>n</code> pairs of parentheses, write a function to <em>generate all combinations of well-formed parentheses</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> n = 3
<strong>Output:</strong> ["((()))","(()())","(())()","()(())","()()()"]
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> n = 1
<strong>Output:</strong> ["()"]
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 8</code></li>
</ul>

class Solution:
    def generateParenthesis(self, n: int) -> List[str]:
        brackets_comb = []
        #TWO DECISIONS OR (I CAN SAY OPTIONS LIKE TREE HAS EITHER LEFT OR RIGHT)
        #1. WHEN TO ADD OPEN BRACKET 
        #2. WHEN TO CLOSE BRACKET 

        def dfs_combination(openCount, closeCount, comb_list):
            
            #BASE CONDITIONS
            if len(comb_list) == 2*n: #total lenght will handle both case of limiting Open&Close to n
                found_comb = "".join(comb_list) 
                brackets_comb.append(found_comb)
                return 
            
            #Execution
            if openCount < n: #Open bracket has perference but dont go over limit
                comb_list.append("(")
                dfs_combination(openCount + 1, closeCount, comb_list)
                comb_list.pop()
            if openCount > closeCount: #There should be more open brackets inorder to proceed for closing
                comb_list.append(")")
                dfs_combination(openCount, closeCount + 1, comb_list)
                comb_list.pop()

        dfs_combination(0,0,[])

        return brackets_comb



        
        
16600