Java solution with stack and explanation
This works because if the parentheses is outer most and it is a closing parenthese then the size of the stack has to be equal to one. If the parenthese is openi
This works because if the parentheses is outer most and it is a closing parenthese then the size of the stack has to be equal to one. If the parenthese is opening then the size should be 0. Other wise they are inear parentheses.\n```\npublic String removeOuterParentheses(String S) {\n\tStringBuilder s = new StringBuilder();\n\tStack<Character> h = new Stack<>();\n\n\tfor (int i = 0; i < S.length(); i++) {\n\t\tif (h.size() == 1 && S.charAt(i) == \')\'){\n\t\t\th.pop();\n\t\t}\n\t\telse if (h.size() == 0 && S.charAt(i) == \'(\'){\n\t\t\th.push(\'(\');\n\t\t}\n\t\telse if (S.charAt(i) == \')\'){\n\t\t\ts.append(")");\n\t\t\th.pop();\n\t\t}\n\t\telse if (S.charAt(i) == \'(\'){\n\t\t\ts.append("(");\n\t\t\th.push(\'(\');\n\t\t}\n\t}\n\treturn s.toString();\n}\n```
['Stack', 'Java']