C++ | Stack | O(N)
\nstring minRemoveToMakeValid(string s) {\n\tstack<int> st;\n\tfor (int i = 0; i < s.length(); i++) {\n\t\tif (s[i] == \'(\') {\n\t\t\tst.push(i);\n\t\t} else i
```\nstring minRemoveToMakeValid(string s) {\n\tstack<int> st;\n\tfor (int i = 0; i < s.length(); i++) {\n\t\tif (s[i] == \'(\') {\n\t\t\tst.push(i);\n\t\t} else if (s[i] == \')\') {\n\t\t\tif (!st.empty())\n\t\t\t\tst.pop();\n\t\t\telse\n\t\t\t\ts[i] = \'*\';\n\t\t}\n\t}\n\n\twhile (!st.empty()) {\n\t\ts[st.top()] = \'*\';\n\t\tst.pop();\n\t}\n\n\tstring ans;\n\tfor (auto ch : s) {\n\t\tif (ch != \'*\') {\n\t\t\tans += ch;\n\t\t}\n\t}\n\treturn ans;\n}\n```
['Stack', 'C']