FastPrepConfigurable Valid Parentheses

Configurable Valid Parentheses

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREEN
Learn

Problem statement

Each two-character string in pairs gives an opening and its matching closing character. Ignore text characters absent from all pairs. Return true when configured delimiters are correctly nested and completely closed.

Function

validConfiguredParentheses(text: String, pairs: String[]) → boolean

Examples

Example 1

text = "x<aAb>y"pairs = ["<>","aA","bB"]return = false

The closer b does not match the expected A.

Constraints

  • Every pair has length two.
  • Pair characters are globally distinct.
  • text.length <= 10^6.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public boolean validConfiguredParentheses(String text, String[] pairs) {
  // Write your code here.
}
text"x<aAb>y"
pairs["<>","aA","bB"]
expectedfalse
Checking account…