Minimum Remove to Make Valid Parentheses
Minimum Remove to Make Valid Parentheses
Given a string s consisting of '(', ')', and lowercase English characters, remove the minimum number of parentheses to make the resulting string a valid parentheses string. Return any one of the possible valid strings.
A parentheses string is considered valid if:
- It is empty.
- It contains only lowercase characters.
- It can be represented as
AB, whereAandBare valid strings. - It can be represented as
(A), whereAis a valid string.
Example 1:
Input: s = "lee(t(c)o)de)" Output: "lee(t(c)o)de" Explanation: Other valid outputs include "lee(t(co)de)" and "lee(t(c)ode)".
Example 2:
Input: s = "a)b(c)d" Output: "ab(c)d"
Example 3:
Input: s = "))((" Output: "" Explanation: An empty string is a valid output.
Constraints:
1 <= s.length <= 10^5s[i]is either'(',')', or a lowercase English letter.
Similar LeetCode problem: Minimum Remove to Make Valid Parentheses
AI interview prep
Core dilemma
Minimizing removals while ensuring structural validity of parentheses.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Minimum Remove to Make Valid Parentheses
Minimum Remove to Make Valid Parentheses
Given a string s consisting of '(', ')', and lowercase English characters, remove the minimum number of parentheses to make the resulting string a valid parentheses string. Return any one of the possible valid strings.
A parentheses string is considered valid if:
- It is empty.
- It contains only lowercase characters.
- It can be represented as
AB, whereAandBare valid strings. - It can be represented as
(A), whereAis a valid string.
Example 1:
Input: s = "lee(t(c)o)de)" Output: "lee(t(c)o)de" Explanation: Other valid outputs include "lee(t(co)de)" and "lee(t(c)ode)".
Example 2:
Input: s = "a)b(c)d" Output: "ab(c)d"
Example 3:
Input: s = "))((" Output: "" Explanation: An empty string is a valid output.
Constraints:
1 <= s.length <= 10^5s[i]is either'(',')', or a lowercase English letter.
Similar LeetCode problem: Minimum Remove to Make Valid Parentheses