The Minimum Remove to Make Valid Parentheses problem gives you a string containing lowercase letters and parentheses. Your task is to remove the minimum number of parentheses so that the resulting string is valid — meaning every open bracket has a matching close bracket in the correct order. This Minimum Remove to Make Valid Parentheses coding problem is a staple of stack-based string manipulation.
This problem is a favorite at Meta, Apple, Amazon, Netflix, Google, Microsoft, and Bloomberg because it directly tests stack usage for bracket matching — a fundamental pattern that appears across compilers, expression evaluators, and code formatters. The string and stack interview pattern is cleanly demonstrated, and the problem has a satisfying, elegant solution that interviewers love to see candidates arrive at naturally.
The approach uses a stack to track unmatched indices. Traverse the string: push the index of every '(' onto the stack. When you encounter ')', pop from the stack if it's non-empty (a match is found). If the stack is empty for ')', mark this ')' for removal. After the traversal, any indices remaining in the stack are unmatched '(' — mark them too. Build the result string by skipping all marked indices.
String: "a(b(c)d)".
"a(b(c)d)" — already valid.String: "a)b(":
"ab".Minimum Remove to Make Valid Parentheses is an excellent problem to rehearse two-pass stack techniques. In the first pass, identify invalid indices; in the second pass, build the result. This two-pass approach is cleaner than trying to reconstruct in a single pass. Practice explaining your stack-usage reasoning aloud — interviewers value clear verbal articulation for stack problems, which can otherwise feel tricky to describe.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Score of Parentheses | Medium | Solve | |
| Remove All Adjacent Duplicates in String II | Medium | Solve | |
| Reverse Substrings Between Each Pair of Parentheses | Medium | Solve | |
| Simplify Path | Medium | Solve | |
| Maximum Nesting Depth of Two Valid Parentheses Strings | Medium | Solve |