15% off all plans & roadmaps Use code
See plansLeetCode 1249 · Solution & editorial
Given a string s of '(' , ')' and lowercase English characters.
Minimum Remove to Make Valid Parentheses is a Stack Patterns problem, in the Valid Parentheses Matching subpattern. The pattern covers parentheses matching, monotonic stack, histogram, and expression evaluation
Master parentheses validation and balancing using stack. Handle multiple bracket types and minimum additions.
The reference solution runs in O(n) time and O(1) space.
Minimum Remove to Make Valid Parentheses has been reported in interviews at Facebook, ByteDance, Bloomberg, Amazon, Goldman Sachs, LinkedIn, Apple.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Minimum Remove to Make Valid Parentheses is a Stack Patterns problem, in the Valid Parentheses Matching subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.