<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 {
public:

    void recursive(vector<string> &combo, string curr_combo, stack<char> open_brack, int n_open, int n_close)
    {
        if(n_open == 0 && n_close == 0)
        {
            if(open_brack.size() == 0)
            {
                combo.push_back(curr_combo);
                return;
            }
        }

        // add the open brack
        if(n_open > 0)
        {
            open_brack.push('(');
            curr_combo.push_back('(');
            recursive(combo, curr_combo, open_brack, n_open - 1, n_close);
            open_brack.pop();
            curr_combo.pop_back();
        }

        if(n_close > 0 && open_brack.empty() == false)
        {
            open_brack.pop();
            curr_combo.push_back(')');
            recursive(combo, curr_combo, open_brack, n_open, n_close - 1);
        }

        return;
    }
    

    vector<string> generateParenthesis(int n) 
    {
        vector<string> final_combo;
        string curr_combo;
        stack<char> open_brack;

        recursive(final_combo, curr_combo, open_brack, n, n);

        return final_combo;
    }
};
30625