Python solution using stack and maintaining counter
Before I explain any further get this, let\'s say for each "(" you get you put -1 and for each ")" you get you put +1 to the counter varriable and because of th
# Before I explain any further get this, let\'s say for each "(" you get you put -1 and for each ")" you get you put +1 to the counter varriable and because of that whenever we encounter a valid paranthese our sum will be zero for example for (()())(()) can be decomposed to (()()) + (()) note that for each valid decomposition our sum will be zero. Example (()) -1-1+1+1 ==0 also for (()()) -1-1+1-1+1+1==0 for each time our sum is zero we are looking at a valid decompostion and hence at that moment we take what we have in our stack and remove the outter brackets which is done easily using stack[1:-1] it will exlude the first and last from our stack and we add this value to our answer list and make our stack empty again for future decompistion, we repeat this and return the " ".join(final_answer) here final answer is the list that has all the decompositions with there outter barckets removed. Upvote if you liked the approch. Thanks\n\n\n```\nclass Solution:\n    def removeOuterParentheses(self, s: str) -> str:\n        stack = []\n        final_answer = []\n        counter=0\n        for val in s:\n            stack.append(val)\n            if val==\'(\':\n                counter+=1\n            elif val==\')\':\n                counter-=1\n            if counter==0:\n                final_answer+=stack[1:-1]\n                stack=[]\n        \n        return "".join(final_answer)\n```
['Stack', 'Python']