Python 3 using stack simple solution with explanation
\nclass Solution:\n    def minAddToMakeValid(self, S: str) -> int:\n        _stack=[]                                #initilized a new stack\n        for bracke
```\nclass Solution:\n    def minAddToMakeValid(self, S: str) -> int:\n        _stack=[]                                #initilized a new stack\n        for bracket in S:                        # looping through all the brackets in S, storing each in bracket variable\n            if(len(_stack)==0):                  # checking if the stack is empty then\n                _stack.append(bracket)           # push the bracket to the empty stack\n            else:                                # else\n                curr=_stack[len(_stack)-1]       #storing the top of the stack to the curr variable\n                if curr ==\'(\' and bracket ==\')\': #checking if the curr has opening and the bracket has closing bracket then the bracket from the stack is poped \n                     _stack.pop()\n                else:                            # else the bracket will be added to the stack\n                    _stack.append(bracket)\n                    \n        return len(_stack)                       #returning the lenght of the stack - it contains all the invalid paranthesis \n\n```
['Stack', 'Python3']