JAVA }} O(n) || Easy Approach With comment
\nclass Solution\n{\n    public String removeOuterParentheses(String S) \n    {\n        Stack<Character> valid=new Stack<>();//checking the balance and when th
```\nclass Solution\n{\n    public String removeOuterParentheses(String S) \n    {\n        Stack<Character> valid=new Stack<>();//checking the balance and when the stack is Empty\n        List<Integer> index=new ArrayList<>();//for storing the index\n        char ch;\n        \n        for(int i=0;i<S.length();i++)//traversering the indices \n        {\n            ch=S.charAt(i);//extracting charracter\n            if(valid.isEmpty())//new valid parentheses \n            {\n                valid.push(ch);//pushing it into the stack the open parentheses \n                index.add(i);//and pushing it corresponding index \n            }\n            else if(ch==\')\'&&valid.peek()==\'(\')\n            {\n                valid.pop();\n                if(valid.isEmpty())//ending of new valid parentheses\n                   index.add(i);//storing the closing index \n            }\n            else\n            {\n                valid.push(ch);//otherwise pushing he open parentheses \n            }\n        }\n        StringBuilder res=new StringBuilder();//resultant \n        for(int i=0;i<index.size();i+=2)//index is always in pair i.e;starting and ending \n        {\n            res.append(S.substring(index.get(i)+1,index.get(i+1)));//removing the outmost parenthesis for the given pair of indices \n        }\n        return res.toString();//returning the String \n    }\n}//Please do vote me, It helps a lot\n```
['Stack', 'Java']