Easy to understand Python with comments
Python\nclass Solution:\n    def removeOuterParentheses(self, S: str) -> str:\n        res = \'\'\n        stack = []\n        \n        # basket is used to sto
```Python\nclass Solution:\n    def removeOuterParentheses(self, S: str) -> str:\n        res = \'\'\n        stack = []\n        \n        # basket is used to store previous value\n        basket = \'\'\n        \n        for p in S:\n            if p == \'(\':\n                stack.append(p)\n            else:\n                stack.pop()\n            basket += p\n            \n            # if the stack is empty it means we have a valid\n            # decomposition. remove the outer parentheses\n            # and put it in the result/res. make sure to\n            # clean up the basket though!\n            if not stack:\n                res += basket[1:-1]\n                basket = \'\'\n                \n        return res\n```
['Stack', 'Python']