JavaScript counter solution
\n/**\n * @param {string} S\n * @return {string}\n */\nvar removeOuterParentheses = function(S) {\n    let counter = 0;\n    let result = \'\';\n    \n    for (
```\n/**\n * @param {string} S\n * @return {string}\n */\nvar removeOuterParentheses = function(S) {\n    let counter = 0;\n    let result = \'\';\n    \n    for (let i = 0; i < S.length; i++) {\n        if ((S[i] === \'(\' && ++counter !== 1) || (S[i] === \')\' && --counter !== 0)) {\n            result += S[i];\n        }\n    }\n    \n    return result;\n};\n```
['JavaScript']