Problem
Ask
Submissions

Problem: Remove Invalid Parentheses

Medium
30 min
Explore the backtracking algorithm to remove invalid parentheses from a string. Understand how to generate all unique valid strings by removing the fewest parentheses, applying a systematic approach that handles nesting and matching. This lesson equips you with skills to solve similar complex string validation problems efficiently.

Statement

You are given a string, s, that contains:

  • Lowercase English letters

  • Opening '(' and closing ')' parentheses

A string is considered valid if:

  1. All opening parentheses '(' are closed properly by a matching ')'.

  2. The parentheses are in the correct order and nesting.

  3. Letters can appear anywhere and do not affect validity.

Return all possible valid strings that can be formed by removing the minimum number of invalid parentheses. The answer must be a list of unique strings, in any order.

Constraints:

  • 11 \leq s.length 25\leq 25

  • s consists of lowercase English letters and parentheses '(' and ')'.

  • There will be at most 20 parentheses in s.

Problem
Ask
Submissions

Problem: Remove Invalid Parentheses

Medium
30 min
Explore the backtracking algorithm to remove invalid parentheses from a string. Understand how to generate all unique valid strings by removing the fewest parentheses, applying a systematic approach that handles nesting and matching. This lesson equips you with skills to solve similar complex string validation problems efficiently.

Statement

You are given a string, s, that contains:

  • Lowercase English letters

  • Opening '(' and closing ')' parentheses

A string is considered valid if:

  1. All opening parentheses '(' are closed properly by a matching ')'.

  2. The parentheses are in the correct order and nesting.

  3. Letters can appear anywhere and do not affect validity.

Return all possible valid strings that can be formed by removing the minimum number of invalid parentheses. The answer must be a list of unique strings, in any order.

Constraints:

  • 11 \leq s.length 25\leq 25

  • s consists of lowercase English letters and parentheses '(' and ')'.

  • There will be at most 20 parentheses in s.