java two solution 1. using stack 2.simple for loop
using Stack\n\nclass Solution {\n    public String removeOuterParentheses(String S) {\n        Stack<Character> st=new Stack();\n        StringBuilder sb=new St
using Stack\n```\nclass Solution {\n    public String removeOuterParentheses(String S) {\n        Stack<Character> st=new Stack();\n        StringBuilder sb=new StringBuilder();\n        for(char ch:S.toCharArray())\n        {\n            if(ch==\'(\')\n            {\n                 if(st.size()>=1)\n                 {\n                     sb.append(ch);\n                 }\n                st.push(ch);\n            }\n            else{\n                if(st.size()>1)\n                 {\n                     sb.append(ch);\n                 }\n                st.pop();\n            }\n        }\n        return sb.toString();\n    }\n}\n```\n\nusing Array\n```\nclass Solution {\n    public String removeOuterParentheses(String S) {\n        int top=-1;\n        String str="";\n        for(int i=0;i<S.length()-1;i++){\n           \n            if(S.charAt(i)==\'(\'&&++top!=0)\n           {\n               str+=S.charAt(i);\n           }\n            else if(S.charAt(i)==\')\'&&--top!=-1)\n            {\n                str+=S.charAt(i);\n            }\n          \n        }\n        return str;\n    }\n}\n```
['Stack', 'Java']