<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p>

<p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</strong>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;()())()&quot;
<strong>Output:</strong> [&quot;(())()&quot;,&quot;()()()&quot;]
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;(a)())()&quot;
<strong>Output:</strong> [&quot;(a())()&quot;,&quot;(a)()()&quot;]
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;)(&quot;
<strong>Output:</strong> [&quot;&quot;]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 25</code></li>
	<li><code>s</code> consists of lowercase English letters and parentheses <code>&#39;(&#39;</code> and <code>&#39;)&#39;</code>.</li>
	<li>There will be at most <code>20</code> parentheses in <code>s</code>.</li>
</ul>

class Solution:
    def removeInvalidParentheses(self, s: str) -> List[str]:
        solutions = [] # Max length 

        currents = [""]
        stack = []
        mapping = {"]": "[", "}": "{", ")": "("}
        def dfs(s: str, stack=[]):
            
            if len(s) == 0:
                if len(stack) == 0:
                    if len(solutions):
                        print(len(currents[0]) , len(solutions[0]), len(currents[0]) > len(solutions[0]))
                    if len(solutions):
                        if len(currents[0]) > len(solutions[0]):
                            while solutions:
                                solutions.pop(0)
                            solutions.append(currents[0])
                        elif  len(currents[0]) == len(solutions[0]):
                            solutions.append(currents[0])
                        else:
                            pass
                    else:
                        solutions.append(currents[0])
                return 
            before = currents[0]
            
            if s[0] in '[({':
                
                
                # Apply 
                stack.append(s[0])                
                currents[0] += s[0]
                dfs(s[1:], stack)

                # Undo 
                stack.pop(-1)
                currents[0] = before

                # Remove 
                dfs(s[1:], stack) # Skip
            elif s[0] in ')}]':
                
                temp = []
                # Apply 
                while len(stack) and stack[-1].isalpha():
                    temp.append(stack.pop(-1))                
                if len(stack) == 0 or mapping[s[0]] != stack[-1]:
                    #not possible to apply 
                    pass
                else:
                    stack.pop(-1)
                    currents[0] += s[0]
                    dfs(s[1:], stack)                    
                    stack.append(mapping[s[0]])
                
                # Undo 
                stack.extend(temp[-1::-1])
                currents[0] = before

                # Remove 
                dfs(s[1:], stack) # Skip
            else:
                currents[0] += s[0]
                dfs(s[1:], stack)
                currents[0] = before

        dfs(s, stack)
        return list(set(solutions))
17000