Skip to content

1249. Minimum Remove to Make Valid Parentheses #261

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

The task is to remove the minimum number of parentheses from a given string to make it a valid parentheses string. A valid parentheses string is defined as:

  • It is empty or contains only lowercase letters.
  • It can be written as AB, where A and B are valid parentheses strings.
  • It can be written as (A), where A is a valid parentheses string.

Key Points

  1. Valid Parentheses String: The number of opening and closing parentheses must match. Each opening parenthesis ( must have a corresponding closing parenthesis ) in a valid order.
  2. Strategy: We need to remove the invalid parentheses while keeping the valid characters (both letters and valid parentheses) in the resulting string.
  3. Two-pass Approach:…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Jan 11, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants