Intuitive stack approach 😮 | O(N) run time ⏱️
\n# Approach\n- Create a vector of size "s" and initialize all the values to be zero, representing whether each character in the input string is to be added to 
\n# Approach\n- Create a vector of size "s" and initialize all the values to be zero, representing whether each character in the input string is to be added to the resultant string or not.  (0 - ignore, 1 - add).\n- Use a stack which stores only the parentheses and their indices in the string so that it will be easy for us to locate and eliminate.\n- Iterate through the string, pushing only the parentheses onto the stack while checking if there is an opening parentheses ( \' ( \' ) at the top of the stack when encountering a closing parentheses( \' ) \' ). If such a pair exists, pop the top element of the stack as we got a valid pair of parentheses and mark the corresponding indices in the vector as 1 to indicate inclusion in the resultant string.\n- This way we can identify the parentheses that doesn\'t have a pair.\n- If a character is encountered just set the value as 1 in the vector.\n- Finally, add all the characters that are marked as 1 in the vector to form the resultant string.\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    string minRemoveToMakeValid(string s) {\n        stack<pair<char,int>> stk;\n        vector<int> vec(s.size(),0);\n        for(int i=0;i<s.size();i++){\n            if(!stk.empty() && stk.top().first == \'(\' && s[i] == \')\'){\n                int num = stk.top().second; \n                vec[num] = 1;\n                stk.pop();\n                vec[i] = 1;\n            }else if(s[i] == \')\' || s[i] == \'(\'){\n                stk.push(make_pair(s[i],i));\n            }else{\n                vec[i] = 1;\n            }\n        }\n        string res = "";\n        for(int i=0;i<s.size();i++){\n            if(vec[i]){\n                res += s[i];\n            }\n        }\n        return res;\n    }\n};\n```
['C++']