FastPrepRemove Invalid Parentheses

Remove Invalid Parentheses

Bloomberg LP logoBloomberg LP● HardNEW GRADPHONE SCREENONSITE INTERVIEW
Learn

Problem statement

Remove the minimum number of parentheses from text so every remaining parenthesis string is valid. Letters and other non-parenthesis characters cannot be removed.

Return every distinct minimum-removal result in lexicographic order.

Function

removeInvalidParentheses(text: String) → String[]

Examples

Example 1

text = "()())()"return = ["(())()","()()()"]

Removing one closing parenthesis yields the two distinct valid results.

Constraints

  • 0 <= text.length <= 25.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String[] removeInvalidParentheses(String text) {
  // Write your code here.
}
text"()())()"
expected["(())()", "()()()"]
Checking account…