Explained || Optimized || Interview Question || C++
Intuition\n Describe your first thoughts on how to solve this problem. \nitna to samjh aa jaata hai saab, 350 ques karne k baad\n\n# Approach\n Describe your ap
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nitna to samjh aa jaata hai saab, 350 ques karne k baad\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\njust use the stack \n\n# Complexity\n- Time complexity:\nO(n), n is size of given string\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n//see- https://www.youtube.com/watch?v=MLfAFCkzChU\n/* algo:\n   1. check stack empty ? if true then put the 1st char and this will be not ans as it\'s    outermost.\n\n   2. add another cha, check stack is empty or not, if not then it means this char should be in our ans string add it their and then place it inside stack.\n\n   3. add another char if it\'s a closing bracket then remove it\'s opening bracket from stack and check if stack gets empty after this or not, if yes then it was outermost don\'t add in ans, if not empty the this can be added to ans string.\n*/\n\n    string removeOuterParentheses(string s) {\n        stack<char> st;\n        if(s=="" || s=="()") return "";\n        string ans="";\n        int n=s.size();\n        int i=0;\n        while(i<n)\n        {\n            if(st.empty())\n            {\n                st.push(s[i]);\n                \n            }\n            else\n            {\n                if(s[i]==\'(\')\n                {\n                    ans+=s[i];\n                    st.push(s[i]);\n                    \n                }\n                else\n                {\n                    st.pop();\n                    if(!st.empty()) ans+=s[i];\n                }\n            }\n            i++;\n        }\n        return ans;\n// PLEASE UPVOTE THANK YOU\n    }\n};\n```
['C++']