Loading problem…
This problem builds on valid-parentheses. Complete that first, then load your solution to continue.
You're building a code formatter that needs to fix invalid parentheses in user input. Instead of just validating, you need to remove the minimum number of invalid parentheses to make the string valid.
Given a string s containing only the characters '(', ')', and lowercase 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:
removeInvalidParentheses("()())()");
// ["()()()", "(())()"]
// Removed one ')' from position 3 or 4
removeInvalidParentheses("(a)())()");
// ["(a)()()", "(a())()"]
// Removed one ')' to make valid
removeInvalidParentheses(")(");
// [""]
// Both parentheses are invalid, remove bothThis problem models real code formatting features: