Good evening! Here's our prompt for today.
Given a string s
that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid. Return all the possible results.

For example, consider the following string as input:
SNIPPET
1s = "()())()"
The correct solution should return ["(())()","()()()"]
, with both possibilities.
Note: this problem is similar to Minimum Parentheses Removal, with the difference being that we want to return all possible valid string results.
Constraints
- 1 <=
s
.length <= 25 s
consists of lowercase English letters and parentheses'('
and')'
.- There will be at most 20 parentheses in
s
.
Try to solve this here or in Interactive Mode.
How do I practice this challenge?
xxxxxxxxxx
38
var assert = require('assert');
​
function remove_invalid_parenthesis(s) {
return;
}
​
try {
assert.deepEqual(remove_invalid_parenthesis("()()"), ["()()"]);
​
console.log('PASSED: ' + "assert.equal(remove_invalid_parenthesis('()()'), ['()()']");
} catch (err) {
console.log(err);
}
​
try {
assert.deepEqual(remove_invalid_parenthesis("()())()"), ["(())()", "()()()"]);
​
console.log('PASSED: ' + "assert.equal(remove_invalid_parenthesis('()())()')), ['(())()','()()()'])");
} catch (err) {
console.log(err);
}
​
try {
assert.deepEqual(remove_invalid_parenthesis("(a)())()"), ["(a())()", "(a)()()"]);
​
console.log('PASSED: ' + "assert.equal(remove_invalid_parenthesis('(a)())()'), ['(a())()','(a)()()'])");
} catch (err) {
console.log(err);
}
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment
Here's our guided, illustrated walk-through.
How do I use this guide?
Access all course materials today
The rest of this tutorial's contents are only available for premium members. Please explore your options at the link below.