LeetCode 301, Hard. Topics: String, Backtracking, Breadth-First Search. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 24 parametrized pytest cases, and a playground notebook:
Problem
Given a string s that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.
Return a list of unique strings that are valid with the minimum number of removals. You may return the answer in any order.
Examples
Constraints
1 <= s.length <= 25
s consists of lowercase English letters and parentheses '(' and ')'.
- There will be at most
20 parentheses in s.
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
Last modified on September 7, 2026