Java Stack of Pairs Solution
\nclass Solution {\n    public String minRemoveToMakeValid(String s) {\n        Stack<Pair<Character,Integer>> validStack = new Stack<>();\n        for(int i = 
```\nclass Solution {\n    public String minRemoveToMakeValid(String s) {\n        Stack<Pair<Character,Integer>> validStack = new Stack<>();\n        for(int i = 0; i < s.length(); i++){\n            if(s.charAt(i) == \'(\' || s.charAt(i) == \')\'){\n                char top = s.charAt(i);\n                if(!validStack.isEmpty()) top = validStack.peek().getKey();\n                char curr = s.charAt(i);\n                if(validStack.isEmpty() || curr == top || (curr == \'(\' && top == \')\')){\n                    Pair p = new Pair(curr,i);\n                    validStack.add(p);\n                }\n                else if(curr == \')\' && top == \'(\'){\n                    validStack.pop();\n                }  \n            }\n        }\n        StringBuilder sb = new StringBuilder(s);\n        while(!validStack.isEmpty()){\n            int index = validStack.peek().getValue();\n            sb.deleteCharAt(index);\n            validStack.pop();\n        }\n        return sb.toString();\n    }\n}\n```
[]