Remove Invalid Parentheses
Problem
Imagine you receive a corrupted string of parentheses from a user input or a legacy system, and you need to clean it up by removing the minimum number of invalid parentheses to make it valid again.
Given a string s that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid. Return all possible results in any order. A string is valid if parentheses are balanced and properly closed.
1 ≤ s.length ≤ 10^5s consists of lowercase English letters and parentheses '(' and ')'.Edge cases: Empty string → returns [""]String with no parentheses → returns the string itselfString with all valid parentheses → returns the string itself
Test Cases
t1_01basic
Input
{"s":"()())()"}Expected
["()()()","(())()"]Removing one invalid ')' at different positions yields two valid strings.
t1_02basic
Input
{"s":"(a)())()"}Expected
["(a)()()","(a())()"]Similar to canonical example but with letters; minimal removals yield two valid strings.
