Skip to content

Practice Minimum Remove to Make Valid Parentheses

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1249
LeetCode Problem

Minimum Remove to Make Valid Parentheses

Problem Statement

Remove as few parentheses as possible from s, preserving all lowercase letters and the order of retained characters. Return any resulting string with balanced parentheses: each closing parenthesis matches an earlier opening one and none remain unmatched. Empty strings and strings containing only letters are valid.

Source: Minimum Remove to Make Valid Parentheses on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "lee(t(c)o)de)"
Output
"lee(t(c)o)de"

# Example 2

Input
s = "a)b(c)d"
Output
"ab(c)d"

# Example 3

Input
s = "))(("
Output
""

Constraints

1 <= s.length <= 10^5
s[i] is either '(' , ')', or lowercase English letter.

Related LeetCode Problems

Practice more problems similar to Minimum Remove to Make Valid Parentheses.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.