Constant Space Solution
\n    public String minRemoveToMakeValid(String s) {\n\t\tint openCloseCount = 0;\n\t\tint close = 0;\n\t\tfor (int i = 0; i < s.length(); i++)  if (s.charAt(i)
```\n    public String minRemoveToMakeValid(String s) {\n\t\tint openCloseCount = 0;\n\t\tint close = 0;\n\t\tfor (int i = 0; i < s.length(); i++)  if (s.charAt(i) == \')\') close++;\n\t\t\n        StringBuilder sb = new StringBuilder();\n\t\t\n\t\tfor (char c: s.toCharArray()) {\n\t\t\tif (c == \'(\') {\n\t\t\t\tif (openCloseCount == close) continue;\n\t\t\t\topenCloseCount++;\n\t\t\t} else if (c == \')\') {\n\t\t\t\tclose--;\n\t\t\t\tif (openCloseCount == 0) continue;\n\t\t\t\topenCloseCount--;\n\t\t\t} \n\n\t\t\t\tsb.append(c);\n\t\t}\n\t\treturn sb.toString();\n    }\n```
[]