Python solution beats 99%
Traverse the string S from left to right. Time: O(N).\n\nUse the variable net to record the current net number of parenthese -- \'(\' contributes +1 and \')\' c
Traverse the string `S` from left to right. Time: O(N).\n\nUse the variable `net` to record the current net number of parenthese -- \'(\' contributes +1 and \')\' contributes -1. \n\nThe variable \'start\' is to store the starting index of the next primitive part in \'S\'.\n\nWhenever \'net\' becomes 0, one concludes that from the start position to the current position we have a primitive part. Update `res` by adding this primitive part without the starting \'(\' and the ending \')\'. Also, reset `start`.\n\n```\nclass Solution:\n    def removeOuterParentheses(self, S: str) -> str:\n        net, res, start = 0 , \'\', 0\n        for i in range(len(S)):\n            \n            if S[i] == \'(\':\n                net += 1\n            else:\n                net -= 1\n            \n            if net == 0:\n                res += S[start+1:i]\n                start = i + 1\n        return res\n```
[]